mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
07c6e2852f
Extends on #5927, instead of `.default` we'll expose `.render` which is semantically more correct / mirrors the naming of the custom server API. I've updated the spec in #5927 to reflect this change. (copied from #5927): ```js const http = require('http') const page = require('./.next/serverless/about.js') const server = new http.Server((req, res) => page.render(req, res)) server.listen(3000, () => console.log('Listening on http://localhost:3000')) ```
39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
const express = require('express')
|
|
const http = require('http')
|
|
const path = require('path')
|
|
|
|
module.exports = function start (port = 0) {
|
|
return new Promise((resolve, reject) => {
|
|
const app = express()
|
|
const nextStaticDir = path.join(__dirname, '.next', 'static')
|
|
app.use('/_next/static', express.static(nextStaticDir))
|
|
app.get('/', (req, res) => {
|
|
require('./.next/serverless/pages/index.js').render(req, res)
|
|
})
|
|
app.get('/abc', (req, res) => {
|
|
require('./.next/serverless/pages/abc.js').render(req, res)
|
|
})
|
|
app.get('/fetch', (req, res) => {
|
|
require('./.next/serverless/pages/fetch.js').render(req, res)
|
|
})
|
|
app.get('/dynamic', (req, res) => {
|
|
require('./.next/serverless/pages/dynamic.js').render(req, res)
|
|
})
|
|
app.get('/dynamic-two', (req, res) => {
|
|
require('./.next/serverless/pages/dynamic-two.js').render(req, res)
|
|
})
|
|
app.get('/404', (req, res) => {
|
|
require('./.next/serverless/pages/_error.js').render(req, res)
|
|
})
|
|
const server = new http.Server(app)
|
|
|
|
server.listen(port, (err) => {
|
|
if (err) {
|
|
return reject(err)
|
|
}
|
|
|
|
resolve(server)
|
|
})
|
|
})
|
|
}
|