refactor: rename cli to node and export render

This commit is contained in:
Pooya Parsa 2020-11-03 23:20:19 +01:00
parent 2dbaae6b7d
commit ae0fd1b108
2 changed files with 12 additions and 8 deletions

View File

@ -1,14 +1,16 @@
// @ts-ignore // @ts-ignore
import { render } from '~runtime/server' import { render } from '~runtime/server'
// @ts-ignore
export { render } from '~runtime/server'
const debug = (label, ...args) => console.debug(`> ${label}:`, ...args) async function cli () {
async function main () {
const url = process.argv[2] || '/' const url = process.argv[2] || '/'
debug('URL', url)
const debug = (label, ...args) => console.debug(`> ${label}:`, ...args)
const { html, status, headers } = await render(url) const { html, status, headers } = await render(url)
debug('URL', url)
debug('Status', status) debug('Status', status)
for (const header in headers) { for (const header in headers) {
debug(header, headers[header]) debug(header, headers[header])
@ -17,7 +19,9 @@ async function main () {
console.log('\n', html) console.log('\n', html)
} }
main().catch((err) => { if (require.main === module) {
console.error(err) cli().catch((err) => {
process.exit(1) console.error(err)
}) process.exit(1)
})
}