-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.js
More file actions
58 lines (48 loc) · 1.59 KB
/
server.js
File metadata and controls
58 lines (48 loc) · 1.59 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// ___ __ __
// .' _.-----.-----.--| |__.-----.
// | _| _ | _ | _ | | -__|
// |__| |_____|_____|_____|__|_____|
import express from 'express'
import cors from 'cors'
//services
import DB from './services/db/index.js'
import Redis from './services/cache/redis.js'
import Mixpanel from './services/mixpanel/index.js'
import Notifications from './services/notifications/index.js'
import Crons from './services/crons/index.js'
import Stats from './services/stats/index.js'
import Email from './services/email/index.js'
//middlewares
import rateLimiter from './middleware/rate-limiter.js'
import bodyParser from './middleware/body-parser.js'
import mongoSanitize from './middleware/mongo-sanitize.js'
import logRequest from './middleware/log-request.js'
import verifyRequest from './middleware/verify-request.js'
//api
import api from './api/index.js'
import { appVersion, PORT } from './config/config.js'
import devMigrations from './migrations/dev/index.js'
await DB.connect()
await Redis.connect()
await Mixpanel.connect()
Notifications.start()
Email.start()
Crons.start()
Stats.start()
//create app
const app = express()
//initialize view engine
app.set('view engine', 'ejs')
//initialize middlewares
app.use(logRequest)
app.use(bodyParser)
app.use(express.static(process.cwd() + '/public'))
app.use(cors())
app.use(rateLimiter)
app.use(mongoSanitize)
app.use(verifyRequest)
//initialize api
app.get('/', (req, res) => res.send({ message: 'Foodie API running', appVersion }))
app.use('/api', api)
//start server
app.listen(PORT, () => console.log(`server started on port ${PORT}`))