-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
49 lines (39 loc) · 1.25 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
const express = require('express')
const next = require('next')
const fs = require('fs')
const bodyParser = require('body-parser') // turns the body into json object
const colors = require('colors')
// ENV SETUP
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
const port = process.env.PORT || 3000
const expressServer = express()
// Start APP
app.prepare()
.then(() => {
// allows us to send json to our express app
expressServer.use(bodyParser.json())
expressServer.get('/other', (req, res) => {
// console.log(serverLock.getBaseUrl(req));
req.query = {
text: "spencer"
}
console.log(req.query)
return app.render(req, res, '/other', req.query)
})
expressServer.get('/', (req, res) => {
// console.log('SECURE'.red);
// console.log(JSON.stringify(req.secure, null, 2));
// console.log('headers'.red);
// console.log(JSON.stringify(req.headers, null, 2));
return app.render(req, res, '/', req.query)
})
expressServer.get('*', (req, res) => {
return handle(req, res)
})
expressServer.listen(port, (err) => {
if (err) throw err
console.log('> Ready on: ' + port)
})
})