|
|
|
@ -2,6 +2,7 @@ import { dirname, resolve } from 'path'
|
|
|
|
|
import express from 'express'
|
|
|
|
|
import { createServer as createViteServer } from 'vite'
|
|
|
|
|
import { fileURLToPath } from 'url'
|
|
|
|
|
import { readFileSync } from 'fs'
|
|
|
|
|
|
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
|
|
|
|
|
|
|
@ -15,11 +16,15 @@ async function createServer(customHtmlRoutes) {
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
for (const [route, file] of Object.entries(customHtmlRoutes)) {
|
|
|
|
|
app.get(route, (req, res) => {
|
|
|
|
|
app.get(route, async (req, res) => {
|
|
|
|
|
const filePath = resolve(__dirname, file)
|
|
|
|
|
console.log(`Custom Route: %s`, req.url)
|
|
|
|
|
|
|
|
|
|
return res.sendFile(filePath)
|
|
|
|
|
let htmlFile = readFileSync(filePath, 'utf8')
|
|
|
|
|
htmlFile = await vite.transformIndexHtml(req.originalUrl, htmlFile)
|
|
|
|
|
|
|
|
|
|
res.setHeader('Content-Type', 'text/html')
|
|
|
|
|
return res.send(htmlFile)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|