1
0
mirror of https://github.com/sasjs/server.git synced 2025-12-10 19:34:34 +00:00

chore: added desktop mode + drive tmp folder fix

This commit is contained in:
Saad Jutt
2021-11-12 19:43:56 +05:00
parent 514a262340
commit 2eb42408d1
9 changed files with 58 additions and 12 deletions

View File

@@ -1,3 +1,4 @@
import { readFile } from '@sasjs/utils'
import express from 'express'
import path from 'path'
import { getWebBuildFolderPath } from '../../utils'
@@ -5,7 +6,24 @@ import { getWebBuildFolderPath } from '../../utils'
const webRouter = express.Router()
webRouter.get('/', async (_, res) => {
res.sendFile(path.join(getWebBuildFolderPath(), 'index.html'))
const indexHtmlPath = path.join(getWebBuildFolderPath(), 'index.html')
const { MODE } = process.env
if (MODE === 'desktop') {
const content = await readFile(indexHtmlPath)
const codeToInject = `
<script>
localStorage.setItem('accessToken', JSON.stringify('accessToken'))
localStorage.setItem('refreshToken', JSON.stringify('refreshToken'))
</script>`
const injectedContent = content.replace('</head>', `${codeToInject}</head>`)
res.setHeader('Content-Type', 'text/html')
return res.send(injectedContent)
}
res.sendFile(indexHtmlPath)
})
export default webRouter