-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
executable file
·55 lines (38 loc) · 1.31 KB
/
app.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
#!/usr/bin/env node
const fs = require('fs')
const mongoose = require('mongoose')
const AWS = require('aws-sdk')
const log = require('npmlog')
const express = require('express')
const bodyParser = require('body-parser')
const Account = require('./src/server/routes/account')
const Api = require('./src/server/routes/api')
const serverConfig = JSON.parse(fs.readFileSync('server-config.json').toString())
const secretsClient = new AWS.SecretsManager({ region: serverConfig.awsRegion })
const app = express()
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({
extended: true
}))
app.use(express.static('dist'))
// fetch pre-route-registration configurations
secretsClient.getSecretValue({ SecretId: serverConfig.secretId }, (err, data) => {
if (err) throw err
else {
const secret = JSON.parse(data.SecretString)
const JWT_KEY = secret['jwt-token-key']
mongoose.connect(secret['mongo-conn-string'])
app.all('*', (req, res, next) => {
log.http(req.method, req.url)
next()
})
app.use('/account', Account(JWT_KEY))
app.use('/api', Api(JWT_KEY))
app.get('*', (req, res) => {
res.sendFile('./index.html', { root: __dirname })
})
app.listen(serverConfig.port, () => {
log.info('Express', `listening on port:${serverConfig.port}`)
})
}
})