mirror of
https://github.com/sasjs/server.git
synced 2026-04-09 15:13:13 +00:00
fix: adde validation + code improvement
This commit is contained in:
@@ -28,7 +28,7 @@ import { FileTree, isFileTree, TreeNode } from '../types'
|
||||
import { getTmpFilesFolderPath } from '../utils'
|
||||
|
||||
interface DeployPayload {
|
||||
appLoc?: string
|
||||
appLoc: string
|
||||
fileTree: FileTree
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ const deploy = async (data: DeployPayload) => {
|
||||
|
||||
await createFileTree(
|
||||
data.fileTree.members,
|
||||
data.appLoc ? data.appLoc.replace(/^\//, '').split('/') : []
|
||||
data.appLoc.replace(/^\//, '').split('/')
|
||||
).catch((err) => {
|
||||
throw { code: 500, ...execDeployErrorResponse, ...err }
|
||||
})
|
||||
|
||||
@@ -5,18 +5,24 @@ import { publishAppStream } from '../appStream'
|
||||
|
||||
import { multerSingle } from '../../middlewares/multer'
|
||||
import { DriveController } from '../../controllers/'
|
||||
import { fileBodyValidation, fileParamValidation } from '../../utils'
|
||||
import {
|
||||
deployValidation,
|
||||
fileBodyValidation,
|
||||
fileParamValidation
|
||||
} from '../../utils'
|
||||
|
||||
const controller = new DriveController()
|
||||
|
||||
const driveRouter = express.Router()
|
||||
|
||||
driveRouter.post('/deploy', async (req, res) => {
|
||||
try {
|
||||
const response = await controller.deploy(req.body)
|
||||
const { error, value: body } = deployValidation(req.body)
|
||||
if (error) return res.status(400).send(error.details[0].message)
|
||||
|
||||
const data = req.body
|
||||
const appLoc = data.appLoc ? data.appLoc.replace(/^\//, '').split('/') : []
|
||||
try {
|
||||
const response = await controller.deploy(body)
|
||||
|
||||
const appLoc = body.appLoc.replace(/^\//, '')?.split('/')
|
||||
|
||||
publishAppStream(appLoc)
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import path from 'path'
|
||||
import express from 'express'
|
||||
import { folderExists } from '@sasjs/utils'
|
||||
|
||||
import { getTmpFilesFolderPath } from '../../utils'
|
||||
|
||||
const router = express.Router()
|
||||
|
||||
export const publishAppStream = (appLoc: string[]) => {
|
||||
export const publishAppStream = async (appLoc: string[]) => {
|
||||
const appLocUrl = encodeURI(appLoc.join('/'))
|
||||
const appLocPath = appLoc.join(path.sep)
|
||||
|
||||
@@ -16,7 +17,10 @@ export const publishAppStream = (appLoc: string[]) => {
|
||||
'webv'
|
||||
)
|
||||
|
||||
router.use(`/${appLocUrl}`, express.static(pathToDeployment))
|
||||
if (await folderExists(pathToDeployment)) {
|
||||
router.use(`/${appLocUrl}`, express.static(pathToDeployment))
|
||||
console.log('Serving Stream App: ', appLocUrl)
|
||||
}
|
||||
}
|
||||
|
||||
export default router
|
||||
|
||||
@@ -66,6 +66,12 @@ export const registerClientValidation = (data: any): Joi.ValidationResult =>
|
||||
clientSecret: Joi.string().required()
|
||||
}).validate(data)
|
||||
|
||||
export const deployValidation = (data: any): Joi.ValidationResult =>
|
||||
Joi.object({
|
||||
appLoc: Joi.string().pattern(/^\//).required().min(2),
|
||||
fileTree: Joi.any().required()
|
||||
}).validate(data)
|
||||
|
||||
export const fileBodyValidation = (data: any): Joi.ValidationResult =>
|
||||
Joi.object({
|
||||
filePath: Joi.string().pattern(/.sas$/).required().messages({
|
||||
|
||||
Reference in New Issue
Block a user