forked from JeongGoEun/metagalaga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·32 lines (29 loc) · 1006 Bytes
/
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
const express = require('express')
const next = require('next')
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
var favicon = require('serve-favicon')
var path = require('path')
app.prepare()
.then(() => {
const server = express()
server.use(favicon(path.join(__dirname, 'static', 'favicon.ico')))
server.use(function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Headers', 'Accept, X-Access-Token, X-Application-Name, X-Request-Sent-Time')
res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
res.header('Access-Control-Allow-Credentials', 'true')
next()
})
server.get('*', (req, res) => {
handle(req, res).catch(err => {
next(err)
})
return handle(req, res)
})
server.listen(3001, (err) => {
if (err) throw err
console.log('> Ready on http://localhost:3001')
})
})