1
1
mirror of https://github.com/aelve/guide.git synced 2024-11-25 18:56:52 +03:00
guide/front/build/setupProdServer.ts
avele 0336942072
Frontend E2E tests (#404)
Frontend E2E tests
2019-10-29 00:54:54 +04:00

31 lines
1020 B
TypeScript

import path from 'path'
import fs from 'fs'
import { createBundleRenderer } from 'vue-server-renderer'
// TODO move 'src' prefix to config
// TODO do not copy setupDevServer, webpack configs to builded front
// TODO find a way to get rid of ts ignore and still build without errors
// @ts-ignore
import bundle from '../src/vue-ssr-server-bundle.json'
// @ts-ignore
import clientManifest from '../src/vue-ssr-client-manifest.json'
import serve from 'koa-static'
import koaMount from 'koa-mount'
import serverRequestsHandler from './serverRequestsHandler'
const fsAsync = fs.promises
export default async function setupProdServer (app) {
const template = await fsAsync.readFile(path.resolve(__dirname, '../src/index.html'), 'utf-8') as string
const renderer = createBundleRenderer(bundle, {
template,
clientManifest,
runInNewContext: false
})
const handler = (ctx) => serverRequestsHandler(ctx, renderer)
app.use(koaMount('/src', serve(path.resolve(__dirname, '../src/'))))
app.use(handler)
}