-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
51 lines (39 loc) · 1.06 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
42
43
44
45
46
47
48
49
50
51
/**
* @fileoverview This is the server app script.
* @author [email protected] (Alvin Lin)
*/
import cors from 'cors'
import express from 'express'
import http from 'http'
import morgan from 'morgan'
import config from './config.js'
import notesRouter from './server/notesRouter.js'
const app = express()
const server = http.Server(app)
app.set('port', config.PORT)
app.set('view engine', 'pug')
app.use('/dist', cors({
origin: 'https://archiveofourown.org',
optionsSuccessStatus: 200,
}), express.static('dist'))
app.use('/node_modules', express.static('node_modules'))
app.use(morgan('combined'))
app.get('/', (_, response) => {
response.render('index')
})
app.use('/notes', notesRouter)
app.use((_, response) => {
response.status(404).render('error', {
error: '404: Page not found!'
})
})
app.use((error, _, response, __) => {
console.error(error)
response.status(500).render('error', {
error: '500: Internal error!'
})
})
// Starts the server.
server.listen(config.PORT, () => {
console.log(`STARTING SERVER ON PORT ${config.PORT}`)
})