-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
executable file
·82 lines (62 loc) · 2.3 KB
/
server.js
File metadata and controls
executable file
·82 lines (62 loc) · 2.3 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// BASE SETUP
// =============================================================================
// call the packages we need
var argv = require('minimist')(process.argv.slice(2));
var swagger = require("swagger-node-express");
var express = require('express');
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var methodOverride = require('method-override');
var app = express();
var morgan = require('morgan');
var config = require('./config');
var mongoose = require('mongoose');
// configure app
app.use(morgan('dev')); // log requests to the console
// configure body parser
app.use(bodyParser.json()); // parse application/json
app.use(bodyParser.json({ type: 'application/vnd.api+json' })); // parse application/vnd.api+json as json
app.use(bodyParser.urlencoded({ extended: true })); // parse application/x-www-form-urlencoded
app.use(methodOverride('X-HTTP-Method-Override')); // override with the X-HTTP-Method-Override header in the request. simulate DELETE/PUT
// Use the session middleware
app.use(cookieParser());
//-------------
var port = process.env.PORT || 7001; // set our port
// CREATE OUR ROUTER
require('./route')(app);
mongoose.connect(config.database); // connect to database
var db = mongoose.connection;
db.on('error', function(err){
//console.log('DB connection failed with error:', err);
});
db.once('open', function(){
//console.log('DB connected');
})
var subpath = express();
app.use("/v1", subpath);
swagger.setAppHandler(subpath);
app.use(express.static('dist'));
swagger.setApiInfo({
title: "Radioish API",
description: "API to manage User and Posts.",
termsOfServiceUrl: "",
contact: "voltaesaito@hotmail.com",
license: "",
licenseUrl: ""
});
subpath.get('/', function (req, res) {
res.sendfile(__dirname + '/dist/index.html');
});
swagger.configureSwaggerPaths('', 'api-docs', '');
var domain = 'localhost';
if(argv.domain !== undefined)
domain = argv.domain;
else
console.log('No --domain=xxx specified, taking default hostname "localhost".');
var applicationUrl = 'http://' + domain;
swagger.configure(applicationUrl, '1.0.0');
// START THE SERVER
// =============================================================================
app.listen(port);
//console.log('Requests on port:' + port);
exports = module.exports = app;