mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
30 lines
806 B
JavaScript
30 lines
806 B
JavaScript
|
import portFinder from 'portfinder'
|
||
|
import fetch from 'node-fetch'
|
||
|
import qs from 'querystring'
|
||
|
|
||
|
import server from '../../dist/server/next'
|
||
|
import build from '../../dist/server/build'
|
||
|
import _pkg from '../../package.json'
|
||
|
|
||
|
export const nextServer = server
|
||
|
export const nextBuild = build
|
||
|
export const pkg = _pkg
|
||
|
|
||
|
export function findPort () {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
portFinder.getPort((err, port) => {
|
||
|
if (err) return reject(err)
|
||
|
return resolve(port)
|
||
|
})
|
||
|
})
|
||
|
}
|
||
|
|
||
|
export function renderViaAPI (app, pathname, query = {}) {
|
||
|
return app.renderToHTML({}, {}, pathname, query)
|
||
|
}
|
||
|
|
||
|
export function renderViaHTTP (appPort, pathname, query = {}) {
|
||
|
const url = `http://localhost:${appPort}${pathname}?${qs.stringify(query)}`
|
||
|
return fetch(url).then((res) => res.text())
|
||
|
}
|