-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (36 loc) · 1.31 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
37
38
39
40
41
const express = require('express')
const bodyParser = require('body-parser')
const cors = require('cors')
require('dotenv').config();
const app = express()
const router = require('./routes/index')
const { format, transports } = require('winston'),
expressWinston = require('express-winston');
const { timestamp, combine, errors, json } = format
const path = require('path')
// app.use((req, res, next) => {
// res.append("Set-Cookie", "HttpOnly;Secure;SameSite=Strict")
// next()
// })
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cors())
app.use(expressWinston.logger({
format: combine(timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), errors({ stack: true }), json()),
transports: [
new transports.Console(),
new transports.File({ filename: 'logs/app.log' })
],
msg: "HTTP {{req.method}} {{req.url}} {{res.statusCode}} {{res.responseTime}}ms",
expressFormat: false,
meta: false,
statusLevels: true,
ignoreRoute: function (req, res) { return false; }
}))
app.use('/static', express.static(path.join(__dirname, 'uploads')))
app.use('/api/v1', router)
app.get('/', (req, res) => res.send('Services working perfectly.'))
app.listen(process.env.PORT || 3000, () => {
console.log(`PORT: ${process.env.PORT}`)
})
// module.exports = app