-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
48 lines (39 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
44
45
46
47
48
const express = require( 'express' );
const bodyParser = require( 'body-parser' );
const app = express();
app.use( bodyParser.json() );
app.use( bodyParser.urlencoded({ extended: false }) );
app.use( require( 'express-partial-response' )() );
app.use( require( 'morgan' )( 'dev' ) );
app.use( '/v1/awards/', require( './endpoints/awards' ).route() );
app.use( '/v1/vip/', require( './endpoints/vip' ).route() );
app.use( '/v1/categories/', require( './endpoints/categories' ).route() );
app.use( '/v1/mc/', require( './endpoints/mc' ).route() );
app.use( '/v1/members/', require( './endpoints/members' ).route() );
app.get( '/', ( req, res ) => {
let version = require( './package.json' ).version;
res.json({
message: 'Welcome to the prestige system!',
version
});
});
app.use( ( req, res, next ) => {
var err = new Error( 'Not Found' );
err.status = 404;
next( err );
});
require( 'pretty-error' ).start();
app.use( ( err, req, res, next ) => { // eslint-disable-line no-unused-vars
console.error( err.stack );
res.status( err.status || 500 );
res.json({
message: err.message,
status: err.status || 500
});
});
let port = process.env.PORT || '3000';
app.set( 'port', port );
app.listen( port, () => {
console.log( 'Listening on port', port );
});
module.exports = app;