1
0
mirror of https://github.com/sasjs/server.git synced 2026-01-03 21:10:05 +00:00

fix: removed fileExists for serving web

This commit is contained in:
Saad Jutt
2022-05-01 02:28:50 +05:00
parent 6e7f28a6f8
commit 7b39cc06d3

View File

@@ -1,6 +1,6 @@
import path from 'path' import path from 'path'
import express from 'express' import express from 'express'
import { fileExists } from '@sasjs/utils' import { readFile } from '@sasjs/utils'
import { WebController } from '../../controllers/web' import { WebController } from '../../controllers/web'
import { getWebBuildFolderPath, loginWebValidation } from '../../utils' import { getWebBuildFolderPath, loginWebValidation } from '../../utils'
@@ -9,12 +9,16 @@ const webRouter = express.Router()
webRouter.get('/', async (req, res) => { webRouter.get('/', async (req, res) => {
const indexHtmlPath = path.join(getWebBuildFolderPath(), 'index.html') const indexHtmlPath = path.join(getWebBuildFolderPath(), 'index.html')
if (await fileExists(indexHtmlPath)) { try {
res.cookie('XSRF-TOKEN', req.csrfToken()) // Attention! Cannot use fileExists here, due to limitation after building executable
return res.sendFile(indexHtmlPath) const content = await readFile(indexHtmlPath)
}
return res.send('Web Build is not present') res.cookie('XSRF-TOKEN', req.csrfToken())
res.setHeader('Content-Type', 'text/html')
return res.send(content)
} catch (_) {
return res.send('Web Build is not present')
}
}) })
webRouter.post('/login', async (req, res) => { webRouter.post('/login', async (req, res) => {