2018-05-25 12:01:32 +00:00
|
|
|
const express = require('express')
|
|
|
|
const next = require('next')
|
|
|
|
const sitemapAndRobots = require('./sitemapAndRobots')
|
|
|
|
|
|
|
|
const dev = process.env.NODE_ENV !== 'production'
|
|
|
|
|
|
|
|
const port = process.env.PORT || 8000
|
|
|
|
const ROOT_URL = dev
|
|
|
|
? `http://localhost:${port}`
|
|
|
|
: 'https://sitemap-robots.now.sh'
|
|
|
|
|
|
|
|
const app = next({ dev })
|
|
|
|
const handle = app.getRequestHandler()
|
|
|
|
|
|
|
|
// Nextjs's server prepared
|
|
|
|
app.prepare().then(() => {
|
|
|
|
const server = express()
|
|
|
|
|
|
|
|
sitemapAndRobots({ server })
|
|
|
|
|
|
|
|
server.get('*', (req, res) => handle(req, res))
|
|
|
|
|
|
|
|
// starting express server
|
2018-12-17 16:34:32 +00:00
|
|
|
server.listen(port, err => {
|
2018-05-25 12:01:32 +00:00
|
|
|
if (err) throw err
|
|
|
|
console.log(`> Ready on ${ROOT_URL}`) // eslint-disable-line no-console
|
|
|
|
})
|
|
|
|
})
|