mirror of
https://github.com/sasjs/server.git
synced 2025-12-10 19:34:34 +00:00
feat: compile systemInit and inject to autoExec
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { fileExists, readFile } from '@sasjs/utils'
|
||||
import { readFile } from '@sasjs/utils'
|
||||
import express from 'express'
|
||||
import path from 'path'
|
||||
import { getWebBuildFolderPath } from '../../utils'
|
||||
@@ -12,22 +12,23 @@ const codeToInject = `
|
||||
</script>`
|
||||
|
||||
webRouter.get('/', async (_, res) => {
|
||||
const indexHtmlPath = path.join(getWebBuildFolderPath(), 'index.html')
|
||||
if (!(await fileExists(indexHtmlPath))) {
|
||||
let content: string
|
||||
try {
|
||||
const indexHtmlPath = path.join(getWebBuildFolderPath(), 'index.html')
|
||||
content = await readFile(indexHtmlPath)
|
||||
} catch (_) {
|
||||
return res.send('Web Build is not present')
|
||||
}
|
||||
|
||||
const { MODE } = process.env
|
||||
if (MODE?.trim() !== 'server') {
|
||||
const content = await readFile(indexHtmlPath)
|
||||
|
||||
const injectedContent = content.replace('</head>', `${codeToInject}</head>`)
|
||||
|
||||
res.setHeader('Content-Type', 'text/html')
|
||||
return res.send(injectedContent)
|
||||
}
|
||||
|
||||
res.sendFile(indexHtmlPath)
|
||||
return res.send(content)
|
||||
})
|
||||
|
||||
export default webRouter
|
||||
|
||||
Reference in New Issue
Block a user