-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
72 lines (64 loc) · 1.85 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import cookieParser from 'cookie-parser'
import express from 'express'
import morgan from 'morgan'
import UserRouter from './app/routes/UserRouter.js'
import UserSubscription from './app/subscriptions/UserSubscription.js'
import { dev as env } from './config/env/dev.js'
import cors from 'cors'
import path from 'path'
import { expressCspHeader, NONE, SELF } from 'express-csp-header'
import KlaviyoRouter from './app/routes/KlaviyoRouter.js'
class Server {
constructor() {
this.init()
}
init() {
this.app = express()
}
setMiddleware() {
this.app.use(morgan('dev'))
this.app.use(cookieParser())
this.app.use(express.json())
this.app.use(express.urlencoded({ extended: false }))
this.app.use(express.static('public'))
this.app.use(
cors({
origin: 'http://localhost:3000',
})
)
this.app.use(
expressCspHeader({
policies: {
'default-src': [NONE],
'img-src': [SELF],
},
})
)
}
setRoutes() {
/**
* Setting the routes relative to the route
* given.
*/
this.app.use('/users', UserRouter)
this.app.use('/klaviyo', KlaviyoRouter)
/**
* Setting the home route and returning an image
* for testing purposes.
*/
this.app.get('/', async (req, res) => {
res.sendFile(path.resolve('public', 'shiina.png'))
})
}
setSubscriptions() {
// Setting the listen subscription.
UserSubscription.listen()
}
listen() {
// Listen to port.
this.app.listen(env.express.port, () => {
console.log(`Example app listening on port ${env.express.port}`)
})
}
}
export default Server