mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Export render instead of default for serverless target (#5979)
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')) ```
This commit is contained in:
parent
672a87d981
commit
07c6e2852f
|
@ -39,7 +39,7 @@ const nextServerlessLoader: loader.Loader = function () {
|
||||||
import Error from '${absoluteErrorPath}';
|
import Error from '${absoluteErrorPath}';
|
||||||
import App from '${absoluteAppPath}';
|
import App from '${absoluteAppPath}';
|
||||||
import Component from '${absolutePagePath}';
|
import Component from '${absolutePagePath}';
|
||||||
async function render(req, res) {
|
async function renderReqToHTML(req, res) {
|
||||||
const options = {
|
const options = {
|
||||||
App,
|
App,
|
||||||
Document,
|
Document,
|
||||||
|
@ -76,9 +76,9 @@ const nextServerlessLoader: loader.Loader = function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export default async (req, res) => {
|
export async function render (req, res) {
|
||||||
try {
|
try {
|
||||||
const html = await render(req, res)
|
const html = await renderReqToHTML(req, res)
|
||||||
sendHTML(req, res, html, {generateEtags: ${generateEtags}})
|
sendHTML(req, res, html, {generateEtags: ${generateEtags}})
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
|
|
|
@ -8,22 +8,22 @@ module.exports = function start (port = 0) {
|
||||||
const nextStaticDir = path.join(__dirname, '.next', 'static')
|
const nextStaticDir = path.join(__dirname, '.next', 'static')
|
||||||
app.use('/_next/static', express.static(nextStaticDir))
|
app.use('/_next/static', express.static(nextStaticDir))
|
||||||
app.get('/', (req, res) => {
|
app.get('/', (req, res) => {
|
||||||
require('./.next/serverless/pages/index.js').default(req, res)
|
require('./.next/serverless/pages/index.js').render(req, res)
|
||||||
})
|
})
|
||||||
app.get('/abc', (req, res) => {
|
app.get('/abc', (req, res) => {
|
||||||
require('./.next/serverless/pages/abc.js').default(req, res)
|
require('./.next/serverless/pages/abc.js').render(req, res)
|
||||||
})
|
})
|
||||||
app.get('/fetch', (req, res) => {
|
app.get('/fetch', (req, res) => {
|
||||||
require('./.next/serverless/pages/fetch.js').default(req, res)
|
require('./.next/serverless/pages/fetch.js').render(req, res)
|
||||||
})
|
})
|
||||||
app.get('/dynamic', (req, res) => {
|
app.get('/dynamic', (req, res) => {
|
||||||
require('./.next/serverless/pages/dynamic.js').default(req, res)
|
require('./.next/serverless/pages/dynamic.js').render(req, res)
|
||||||
})
|
})
|
||||||
app.get('/dynamic-two', (req, res) => {
|
app.get('/dynamic-two', (req, res) => {
|
||||||
require('./.next/serverless/pages/dynamic-two.js').default(req, res)
|
require('./.next/serverless/pages/dynamic-two.js').render(req, res)
|
||||||
})
|
})
|
||||||
app.get('/404', (req, res) => {
|
app.get('/404', (req, res) => {
|
||||||
require('./.next/serverless/pages/_error.js').default(req, res)
|
require('./.next/serverless/pages/_error.js').render(req, res)
|
||||||
})
|
})
|
||||||
const server = new http.Server(app)
|
const server = new http.Server(app)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue