Repository navigation
Expand file tree
/
Copy pathserver.js
More file actions
executable file
·71 lines (59 loc) · 2.04 KB
/
Copy pathserver.js
File metadata and controls
executable file
·71 lines (59 loc) · 2.04 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
import express from 'express';
import bodyParser from 'body-parser';
import cookieParser from 'cookie-parser';
import path from 'path';
/* -------------------------------- */
/* Initialize development variables */
/* -------------------------------- */
if (process.env.NODE_ENV !== 'production') {
require('./config.js');
console.debug = function() {};
}
// console.debug = console.info;
console.debug = function() {};
/* -------------------------------- */
/* -------------------------------- */
const app = express();
export default app;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
app.use(cookieParser());
/* -------------------- */
/* -------------------- */
if (process.env.WORKER !== 'true') {
// Catch the browser's favicon request. You can still
// specify one as long as it doesn't have this exact name and path.
app.get('/favicon.ico', function(req, res) {
res.writeHead(200, { 'Content-Type': 'image/x-icon' });
res.end();
});
app.use('/static', express.static(path.resolve(__dirname, 'static')));
app.all('/*', function(req, res, next) {
res.header('Access-Control-Allow-Origin', req.headers.origin);
res.header('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type');
res.header('Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE, OPTIONS');
res.header('Access-Control-Allow-Credentials', true);
next();
});
app.use(function (err, req, res, next) {
// Handle errors.
// console.log('Error! ' + err + ', ' + next);
console.log('Error! ' + err);
next();
});
/* ------------------- */
/* API Endpoints */
/* ------------------- */
require('./routes/user.js');
require('./routes/leaderboard.js');
require('./routes/call.js');
require('./routes/interactions.js');
/* ------------------- */
/* ------------------- */
const port = process.env.PORT || 9876;
app.listen(port, (err) => {
if (err) { console.error(err); }
console.info('----\n==> 🌎 API is running on port %s', port);
console.info('==> 💻 Send requests to http://localhost:%s', port);
});
}