-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
41 lines (33 loc) · 1.22 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
import 'dotenv/config.js'
import express from 'express'
import logger from 'morgan'
import cors from 'cors'
import './config/database.js'
import { router as filmsRouter } from './routes/films.js'
import { router as peopleRouter } from './routes/people.js'
import { router as planetsRouter } from './routes/planets.js'
import { router as speciesRouter } from './routes/species.js'
import { router as starshipsRouter } from './routes/starships.js'
import { router as vehiclesRouter } from './routes/vehicles.js'
// Used for seeding database
// import { router as seedsRouter } from './routes/seeds.js'
const app = express()
app.use(cors())
app.use(logger('dev'))
app.use(express.json())
app.use(express.urlencoded({ extended: false }))
app.use('/api/films', filmsRouter)
app.use('/api/people', peopleRouter)
app.use('/api/planets', planetsRouter)
app.use('/api/species', speciesRouter)
app.use('/api/starships', starshipsRouter)
app.use('/api/vehicles', vehiclesRouter)
// Used for seeding database
// app.use('/api/seeds', seedsRouter)
app.use(function (req, res, next) {
res.status(404).json({ err: 'Not found' })
})
app.use(function (err, req, res, next) {
res.status(err.status || 500).json({ err: err.message })
})
export { app }