-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
54 lines (45 loc) · 1.44 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
const express = require('express')
const cors = require('cors')
const path = require('path')
const bodyParser = require('body-parser')
const models = require('./models/')
const config = require('./config/config')
const usersRoutes = require('./routes/users')
const oauthRoutes = require('./routes/oauth')
const filmsRoutes = require('./routes/films')
const torrentRoutes = require('./routes/torrent')
//TODO for dev only
const seed = require('./dev/seed')
const whitelist = [
'http://localhost:8080',
'https://unruffled-benz-398ce5.netlify.com',
]
const corsOptions = {
origin: function (origin, callback) {
//TODO update later: now allowing origin to be undefined for local tests
if (!origin || whitelist.indexOf(origin) !== -1) {
callback(null, true)
} else {
callback(new Error('Not allowed by CORS'))
}
},
}
const app = express()
app.use(cors(corsOptions))
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())
app.use('/users', usersRoutes)
app.use('/oauth', oauthRoutes)
app.use('/films', filmsRoutes)
app.use('/static', express.static(path.join(__dirname, 'uploads', 'subtitles')))
app.use('/torrent', torrentRoutes)
//force:true to drop all tables every time
models.dbc.sync({ force: true }).then(function () {
//TODO for dev only
seed.testUser();
app.listen(config.port, () => {
console.log('Server running on port %s', config.port)
app.emit('appStarted')
})
})
module.exports = app