-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.js
More file actions
38 lines (35 loc) · 1.07 KB
/
app.js
File metadata and controls
38 lines (35 loc) · 1.07 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
import express from 'express';
import path from 'path';
import compression from 'compression';
import favicon from 'serve-favicon';
import bodyParser from 'body-parser';
import morganLogger from 'morgan';
import winston from 'winston';
import dotenv from 'dotenv';
import apiRoutes from './server/routes/index';
dotenv.config();
const port = process.env.PORT || 3000;
const app = express();
// Create winston logger
const logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)({ colorize: true })
]
});
app.use(morganLogger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(compression());
app.use('/uploads', express.static(path.join(__dirname, 'server/uploads')));
app.use(express.static(path.join(__dirname, 'dist')));
// app.use(favicon(path.join(__dirname, 'favicon2.ico')));
apiRoutes(app);
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'dist/index.html'));
});
app.listen(port, (err) => {
if (err) {
return logger.error(err);
}
logger.info('app running on port', port);
});