-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (34 loc) · 1.2 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
const express = require('express');
const morgan = require('morgan');
const bodyParser = require('body-parser');
const settings = require('./config');
const app = express();
// Use morgan so we can get detailed requests logging
app.use(morgan('dev'));
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
process.env.NODE_ENV = "testCloud";
//Make sure that all routes will have to be authenticated
app.use('/user', require('./routes/user.routes'));
app.use('/thread', require('./routes/thread.routes'));
app.use('/comment', require('./routes/comment.routes'));
app.use('/friend', require('./routes/friend.routes'));
// This will be called when no other routes are found
app.use('*', function (req, res, next) {
console.log('This endpoint does not exist');
let message = {
error: "This endpoint does not exist"
};
next(message)
});
// This will handle all errors
app.use((err, req, res, next) => {
console.log('Catch-all error handler was called.');
console.log(err);
res.status(404).json(err).end()
});
const port = process.env.PORT || settings.webPort;
app.listen(port, () => {
console.log('Server running on: ' + port)
});
module.exports = app;