-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
59 lines (48 loc) · 1.75 KB
/
index.js
File metadata and controls
59 lines (48 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import express from 'express';
import apiv1Router from './server/v1/routes/';
import apiv2Router from './server/v2/routes/';
import swaggerUi from 'swagger-ui-express';
import docs from './swagger.json';
import Sequelize from 'sequelize';
const app = express();
const docsUrl = 'https://free-mentors-app.herokuapp.com/api/v1/api-docs/';
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
//intialize routes vesrion 1
app.use('/api/v1',apiv1Router);
//intialize routes vesrion 2
app.use('/api/v2',apiv2Router);
//intialize endpoint of api documatation of vesrion 1
app.use('/api/v1/api-docs', swaggerUi.serve, swaggerUi.setup(docs));
//intialize endpoint of api documatation of vesrion 1
app.use('/api/v2/api-docs', swaggerUi.serve, swaggerUi.setup(docs));
app.get('/',(req, res, next) => res.status(200).send({
status : 200,
message : 'welcome to the Free mentor Api, below link is how to use it',
documentation : `For the documentaion visit this link ${docsUrl}`,
}));
app.use('**', (req, res) => res.status(405).send({
status : 405,
message : `The requested resource was not found on the server, Visit the documentation link ${docsUrl}`
}));
const db = new Sequelize('free-mentor', 'postgres', 'johnkey', {
host: 'localhost',
dialect:'postgres',
});
db.authenticate()
.then(() => console.log('Database Connected'))
.catch(err => console.log('Error '+err));
const test = async()=>{
try{
await db.authenticate();
console.log('Connection has been established successfully.');
} catch (error) {
console.error('Unable to connect to the database:', error);
}
}
test();
//listen for requests
app.listen(process.env.PORT || 3000,function(){
console.log('Now listening for request on port 3000');
});
export default app;