-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
52 lines (41 loc) · 1.25 KB
/
index.ts
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
import bodyParser from 'body-parser'
import compression from 'compression'
import cors from 'cors'
import * as dotenv from 'dotenv'
import express from 'express'
import helmet from 'helmet'
import * as path from 'path'
import errorHandler from './middlewares/error-handler'
import logger from './middlewares/logger'
import router from './router'
dotenv.config()
const app = express()
const port = process.env.PORT || 3000
// serve static files
app.use(express.static(path.join(__dirname, '../public')))
// Response compression //
// https://www.npmjs.com/package/compression //
app.use(compression())
// HTTP Headers / Security //
// https://www.npmjs.com/package/helmet //
app.use(helmet())
// Parse incoming requests and append data to `req.body` //
// https://www.npmjs.com/package/body-parser //
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
// Enable CORS requests //
// https://www.npmjs.com/package/cors //
app.use(cors())
// Log events //
app.use(logger)
// Routes
app.use('/', router)
// Custom Error Handler
app.use(errorHandler)
app.listen(port, () => {
if (process.env.PORT) {
console.log(`App listening at port: ${port}`)
} else {
console.log(`App listening at http://localhost:${port}`)
}
})