mirror of
https://github.com/sasjs/server.git
synced 2026-01-11 16:20:06 +00:00
chore: docker configured for development api+web+mongodb
This commit is contained in:
@@ -13,8 +13,8 @@ dotenv.config()
|
||||
|
||||
const app = express()
|
||||
|
||||
const { MODE } = process.env
|
||||
if (MODE?.trim() !== 'server') {
|
||||
const { MODE, CORS } = process.env
|
||||
if (MODE?.trim() !== 'server' || CORS?.trim() === 'enable') {
|
||||
console.log('All CORS Requests are enabled')
|
||||
app.use(cors({ credentials: true, origin: 'http://localhost:3000' }))
|
||||
}
|
||||
@@ -27,6 +27,10 @@ app.use('/', webRouter)
|
||||
app.use('/SASjsApi', apiRouter)
|
||||
app.use(express.json({ limit: '50mb' }))
|
||||
|
||||
app.use(express.static(getWebBuildFolderPath()))
|
||||
try {
|
||||
app.use(express.static(getWebBuildFolderPath()))
|
||||
} catch (err) {
|
||||
console.error('Unable to get web build')
|
||||
}
|
||||
|
||||
export default connectDB().then(() => app)
|
||||
|
||||
@@ -1,22 +1,29 @@
|
||||
import { readFile } from '@sasjs/utils'
|
||||
import { fileExists, readFile } from '@sasjs/utils'
|
||||
import express from 'express'
|
||||
import path from 'path'
|
||||
import { getWebBuildFolderPath } from '../../utils'
|
||||
|
||||
const webRouter = express.Router()
|
||||
|
||||
const codeToInject = `
|
||||
<script>
|
||||
localStorage.setItem('accessToken', JSON.stringify('accessToken'))
|
||||
localStorage.setItem('refreshToken', JSON.stringify('refreshToken'))
|
||||
</script>`
|
||||
|
||||
webRouter.get('/', async (_, res) => {
|
||||
const indexHtmlPath = path.join(getWebBuildFolderPath(), 'index.html')
|
||||
let indexHtmlPath: string
|
||||
|
||||
try {
|
||||
indexHtmlPath = path.join(getWebBuildFolderPath(), 'index.html')
|
||||
} catch (err) {
|
||||
return res.send('Web Build is not present')
|
||||
}
|
||||
|
||||
const { MODE } = process.env
|
||||
if (MODE?.trim() !== 'server') {
|
||||
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')
|
||||
|
||||
Reference in New Issue
Block a user