-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
57 lines (45 loc) · 1.6 KB
/
index.js
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
const express = require('express');
const app = express();
const routes = require('./routes');
const bodyParser = require('body-parser');
const path = require('path');
const swaggerJsDoc = require('swagger-jsdoc');
const swaggerUi = require('swagger-ui-express');
const swaggerOptions = {
swaggerDefinition: {
info: {
title: 'Airline API',
description: "https://github.com/rumeshmadhusanka/DB-API",
contact: {
name: 'https://github.com/rumeshmadhusanka/DB-API'
},
host: 'http://localhost:3000',
basePath: '/'
}
},
apis: ['./routes/**/**.yaml']
};
const swaggerDocs = swaggerJsDoc(swaggerOptions);
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocs));
// app.use(express.json());
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', '*');
res.setHeader("Access-Control-Allow-Credentials", true);
res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization,x-access-token");
res.setHeader('Access-Control-Expose-Headers', '*');
//Access-Control-Expose-Headers: *
next();
});
//serving static files from public folder
app.use('/public', express.static(path.resolve(__dirname, './public')));
// support parsing of application/json type post data
app.use(bodyParser.json());
//routes
routes(app);
//server
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log("Server is listening to port " + port);
});
module.exports = app;