forked from Eureka-Project/Eureka-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
43 lines (32 loc) · 1.27 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
var express = require('express');
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var helpers = require('./server/helpers.js');
module.exports = app = express();
app.set('port', (process.env.PORT || 3000));
// Set up express formatting.
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
// Redirect requests for local files to the './public' directory.
app.use(express.static(__dirname + '/public'));
// Decode the client's token (if it exists) for all http requests.
// app.use(helpers.decodeToken);
// Initialize routers.
var usersRouter = express.Router();
var linksRouter = express.Router();
var upvotesRouter = express.Router();
// Configure routers.
require('./server/users/usersRoutes.js')(usersRouter);
require('./server/links/linksRoutes.js')(linksRouter);
require('./server/upvotes/upvotesRoutes.js')(upvotesRouter);
// Set up route forwarding.
app.use('/api/users', usersRouter);
app.use('/api/upvote', upvotesRouter);
app.use('/api/links', linksRouter);
// Handle uncaught errors.
app.use(helpers.errorLogger);
app.use(helpers.errorHandler);
// Run the server.
app.listen(app.get('port'), function(){
console.log('Node app is running on port', app.get('port'));
});