-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
41 lines (34 loc) · 1.01 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
require('dotenv').config()
const db = require('./database/conn')
const express = require('express')
const app = express()
const PORT = process.env.PORT || 3000
const cors = require('cors')
const seed = require('./seeders/seed')
const routes = require('./routes/index')
const { errorHandler } = require('./utils/errorHandler')
const corsOptions = { origin: process.env.ALLOW_ORIGIN }
app.use(cors(corsOptions))
app.use(express.json())
app.use(express.urlencoded({ extended: false }))
// for production
db.sequelize.sync()
.then(() => {
seed.seedAdmin()
console.log('Synced db.')
})
.catch((err) => {
console.log('Failed to sync db: ' + err.message)
})
//* *only for development
// db.sequelize.sync({ force: true }).then(() => {
// console.log('Drop and re-sync db.')
// seed.seedAdmin()
// }).catch((err) => {
// console.log('Failed to sync db: ' + err.message)
// })
app.use('/api', routes)
app.use(errorHandler)
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`)
})