-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.js
36 lines (31 loc) · 1.01 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
import express from 'express';
import http from 'http';
import path from 'path';
import morgan from 'morgan';
import logger from './services/logger';
(async () => {
const app = express();
app.disable('x-powered-by');
app.set('trust proxy', true);
app.use(express.json({
limit: '20mb',
}))
.use(morgan(':method :url :status - :response-time ms', {
skip: (req, res) => res.statusCode < 400, stream: process.stderr,
}))
.use(morgan(':method :url :status - :response-time ms', {
skip: (req, res) => res.statusCode >= 400, stream: process.stdout,
}))
.use(express.static(path.join(process.cwd(), './public'), {
maxAge: (60 * 60 * 24 * 7) * 1000,
}));
const router = new express.Router();
router.get('/', (req, res) => {
res.redirect('/index.html');
});
app.use(router);
const httpServer = http.createServer(app);
httpServer.listen(process.env.PORT || 3000, () => {
logger.info(`Express HTTP server started: ${JSON.stringify(httpServer.address())}`);
});
})();