mirror of
https://github.com/sasjs/server.git
synced 2026-01-14 09:20:06 +00:00
feat: serve deployed streaming apps
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import express from 'express'
|
||||
import { deleteFile } from '@sasjs/utils'
|
||||
|
||||
import { publishAppStream } from '../appStream'
|
||||
|
||||
import { multerSingle } from '../../middlewares/multer'
|
||||
import { DriveController } from '../../controllers/'
|
||||
import { fileBodyValidation, fileParamValidation } from '../../utils'
|
||||
@@ -12,6 +14,12 @@ const driveRouter = express.Router()
|
||||
driveRouter.post('/deploy', async (req, res) => {
|
||||
try {
|
||||
const response = await controller.deploy(req.body)
|
||||
|
||||
const data = req.body
|
||||
const appLoc = data.appLoc ? data.appLoc.replace(/^\//, '').split('/') : []
|
||||
|
||||
publishAppStream(appLoc)
|
||||
|
||||
res.send(response)
|
||||
} catch (err: any) {
|
||||
const statusCode = err.code
|
||||
|
||||
22
api/src/routes/appStream/index.ts
Normal file
22
api/src/routes/appStream/index.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import path from 'path'
|
||||
import express from 'express'
|
||||
|
||||
import { getTmpFilesFolderPath } from '../../utils'
|
||||
|
||||
const router = express.Router()
|
||||
|
||||
export const publishAppStream = (appLoc: string[]) => {
|
||||
const appLocUrl = encodeURI(appLoc.join('/'))
|
||||
const appLocPath = appLoc.join(path.sep)
|
||||
|
||||
const pathToDeployment = path.join(
|
||||
getTmpFilesFolderPath(),
|
||||
appLocPath,
|
||||
'services',
|
||||
'webv'
|
||||
)
|
||||
|
||||
router.use(`/${appLocUrl}`, express.static(pathToDeployment))
|
||||
}
|
||||
|
||||
export default router
|
||||
@@ -2,8 +2,15 @@ import { Express } from 'express'
|
||||
|
||||
import webRouter from './web'
|
||||
import apiRouter from './api'
|
||||
import appStreamRouter from './appStream'
|
||||
|
||||
export const setupRoutes = (app: Express) => {
|
||||
app.use('/', webRouter)
|
||||
app.use('/SASjsApi', apiRouter)
|
||||
|
||||
app.use('/AppStream', function (req, res, next) {
|
||||
// this needs to be a function to hook on
|
||||
// whatever the current router is
|
||||
appStreamRouter(req, res, next)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user