You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
765 B
26 lines
765 B
6 months ago
|
'use strict'
|
||
|
const fs = require('fs')
|
||
|
const path = require('path')
|
||
|
const template = fs.readFileSync(
|
||
|
path.join(__dirname, './server/index.html'),
|
||
|
'utf-8'
|
||
|
)
|
||
|
const manifest = require('./server/ssr-manifest.json')
|
||
|
const render = require('./server/entry-server.js').render
|
||
|
|
||
|
exports.main = async (event) => {
|
||
|
const [appHtml, preloadLinks, appContext] = await render(event.path, manifest)
|
||
|
const html = template
|
||
|
.replace(`<!--preload-links-->`, preloadLinks)
|
||
|
.replace(`<!--app-html-->`, appHtml)
|
||
|
.replace(`<!--app-context-->`, appContext)
|
||
|
return {
|
||
|
mpserverlessComposedResponse: true, // 使用阿里云返回集成响应是需要此字段为true
|
||
|
statusCode: 200,
|
||
|
headers: {
|
||
|
'content-type': 'text/html',
|
||
|
},
|
||
|
body: html,
|
||
|
}
|
||
|
}
|