-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
38 lines (30 loc) · 935 Bytes
/
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
const http = require('http');
const path = require('path');
const express = require('express');
const morgan = require('morgan');
const requireAuth = require('./server/require-auth');
const devBuild = require('./server/dev-build');
// config parsing
const env = process.env;
const port = env.PORT || '5000';
const dev = !env.NODE_ENV || env.NODE_ENV === 'development';
const authUser = env.BASIC_AUTH_USER;
const authPass = env.BASIC_AUTH_PASS;
// Express app
const app = express();
app.enable('trust proxy');
app.disable('x-powered-by');
app.use(morgan(dev ? 'dev' : 'short'));
if (authUser) {
app.use(requireAuth(authUser, authPass));
}
if (dev) {
app.use(devBuild());
}
app.use('/', express.static(path.join(__dirname, 'dist')));
// actually listening
const server = http.createServer(app);
server.listen(port, () => {
// eslint-disable-next-line no-console
console.log(`listening on http://localhost:${port}`);
});