-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
47 lines (34 loc) · 1.62 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
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var morgan = require('morgan');
var mongoose = require('mongoose');
var jwt = require('jsonwebtoken'); // used to create, sign, and verify tokens
var config = require('./app/config/config.js'); // get our config file
var apiRoutes = require('./app/config/routes'); // bring in API routes
// =================================================================
// configuration ===================================================
// =================================================================
var port = process.env.PORT || 8080;
mongoose.connect(config.database); // connect to database
//app.set('superSecret', config.secret); // secret variable
// use body parser so we can get info from POST and/or URL parameters
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json({limit: '50mb'}));
// use morgan to log requests to the console
app.use(morgan('dev'));
// serve static files
app.use(express.static(__dirname + '/public'));
// this is the entry way into the client-side
app.get('/', function(request, response) {
response.sendFile(__dirname + '/public/user/index.html');
});
app.get('/admin', function(request, response) {
response.sendFile(__dirname + '/public/admin/index.html');
});
app.use('/api', apiRoutes);
// =================================================================
// start the server ================================================
// =================================================================
app.listen(port);
console.log('Magic happens at http://localhost:' + port);