From 9648c51b5491d8b6bbe5497273efa2d11e2486d2 Mon Sep 17 00:00:00 2001 From: sabhas Date: Fri, 22 Oct 2021 19:17:27 +0000 Subject: [PATCH] feat(api-utility): create getWebBuildFolderPath utility --- api/src/app.ts | 3 ++- api/src/routes/index.ts | 10 ++++++---- api/src/utils/file.ts | 5 ++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/api/src/app.ts b/api/src/app.ts index cf770ab..aebf051 100644 --- a/api/src/app.ts +++ b/api/src/app.ts @@ -1,10 +1,11 @@ import express from 'express' import indexRouter from './routes' import path from 'path' +import { getWebBuildFolderPath } from './utils' const app = express() app.use(express.json({ limit: '50mb' })) app.use('/', indexRouter) -app.use(express.static(path.join(__dirname, '..', '..', 'web', 'build'))) +app.use(express.static(getWebBuildFolderPath())) export default app diff --git a/api/src/routes/index.ts b/api/src/routes/index.ts index a39e0d7..975c494 100644 --- a/api/src/routes/index.ts +++ b/api/src/routes/index.ts @@ -8,16 +8,18 @@ import { FileUploadController } from '../controllers' import { isExecutionQuery, isFileQuery, isFileTree } from '../types' -import { getTmpFilesFolderPath, makeFilesNamesMap } from '../utils' +import { + getTmpFilesFolderPath, + getWebBuildFolderPath, + makeFilesNamesMap +} from '../utils' const router = express.Router() const fileUploadController = new FileUploadController() router.get('/', async (_, res) => { - res.sendFile( - path.join(__dirname, '..', '..', '..', 'web', 'build', 'index.html') - ) + res.sendFile(path.join(getWebBuildFolderPath(), 'index.html')) }) router.post('/deploy', async (req, res) => { diff --git a/api/src/utils/file.ts b/api/src/utils/file.ts index fe09816..3c62504 100644 --- a/api/src/utils/file.ts +++ b/api/src/utils/file.ts @@ -1,5 +1,8 @@ import path from 'path' -import { getRealPath, generateTimestamp } from '@sasjs/utils' +import { getRealPath } from '@sasjs/utils' + +export const getWebBuildFolderPath = () => + getRealPath(path.join(__dirname, '..', '..', '..', 'web', 'build')) export const getTmpFolderPath = () => getRealPath(path.join(__dirname, '..', '..', 'tmp'))