-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
60 lines (48 loc) · 1.43 KB
/
server.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
58
59
60
/*
* @Author: Ali
* @Date: 2017-03-02 10:59:49
* @Last Modified by: Ali
* @Last Modified time: 2017-03-02 13:16:54
*/
'use strict';
/******** Requiring libraries ********/
var express = require('express'),
app = express(),
bodyParser = require('body-parser'),
morgan = require('morgan'),
path = require('path'),
swaggerJSDoc = require('swagger-jsdoc');
/******* Swagger *********/
// swagger definition
var swaggerDefinition = {
info: {
title: 'Node Swagger API',
version: '1.0.0',
description: 'Demonstrating employee directory RESTful API with Swagger',
},
host: 'localhost:8080',
basePath: '/',
};
// options for the swagger docs
var options = {
// import swaggerDefinitions
swaggerDefinition: swaggerDefinition,
// path to the API docs
apis: ['./routes/*.js'],
};
// initialize swagger-jsdoc
var swaggerSpec = swaggerJSDoc(options);
/******** Setting ********/
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.set('port', 8080);
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With, content-type, Authorization');
next();
});
app.use(morgan('dev'));
/******** Routing ********/
app.use(express.static(__dirname + '/dist'));
require('./routes/route.js')(app, swaggerSpec);