From 5e7cecf3ea74845d9bafba9a72ec2d9566787e33 Mon Sep 17 00:00:00 2001 From: Saad Jutt Date: Sun, 14 Nov 2021 21:12:10 +0500 Subject: [PATCH] chore: fix for development docker-compose --- api/src/app.ts | 6 +----- api/src/prod-server.ts | 6 +++--- api/src/routes/web/web.ts | 7 ++----- api/src/server.ts | 6 +++--- api/src/utils/file.ts | 2 +- docker-compose.yml | 3 +++ web/.dockerignore | 2 +- 7 files changed, 14 insertions(+), 18 deletions(-) diff --git a/api/src/app.ts b/api/src/app.ts index 9fc77da..7f1efc8 100644 --- a/api/src/app.ts +++ b/api/src/app.ts @@ -27,10 +27,6 @@ app.use('/', webRouter) app.use('/SASjsApi', apiRouter) app.use(express.json({ limit: '50mb' })) -try { - app.use(express.static(getWebBuildFolderPath())) -} catch (err) { - console.error('Unable to get web build') -} +app.use(express.static(getWebBuildFolderPath())) export default connectDB().then(() => app) diff --git a/api/src/prod-server.ts b/api/src/prod-server.ts index 6c6693b..ce9d561 100644 --- a/api/src/prod-server.ts +++ b/api/src/prod-server.ts @@ -1,7 +1,6 @@ import path from 'path' import { readFileSync } from 'fs' import * as https from 'https' -import { configuration } from '../package.json' import appPromise from './app' const keyPath = path.join('..', 'certificates', 'privkey.pem') @@ -13,9 +12,10 @@ const cert = readFileSync(certPath) appPromise.then((app) => { const httpsServer = https.createServer({ key, cert }, app) - httpsServer.listen(configuration.sasJsPort, () => { + const sasJsPort = process.env.PORT ?? 5000 + httpsServer.listen(sasJsPort, () => { console.log( - `⚡️[server]: Server is running at https://localhost:${configuration.sasJsPort}` + `⚡️[server]: Server is running at https://localhost:${sasJsPort}` ) }) }) diff --git a/api/src/routes/web/web.ts b/api/src/routes/web/web.ts index 59792c2..6a366dc 100644 --- a/api/src/routes/web/web.ts +++ b/api/src/routes/web/web.ts @@ -12,11 +12,8 @@ const codeToInject = ` ` webRouter.get('/', async (_, res) => { - let indexHtmlPath: string - - try { - indexHtmlPath = path.join(getWebBuildFolderPath(), 'index.html') - } catch (err) { + const indexHtmlPath = path.join(getWebBuildFolderPath(), 'index.html') + if (!(await fileExists(indexHtmlPath))) { return res.send('Web Build is not present') } diff --git a/api/src/server.ts b/api/src/server.ts index 0c62154..5ea98a8 100644 --- a/api/src/server.ts +++ b/api/src/server.ts @@ -1,10 +1,10 @@ import appPromise from './app' -import { configuration } from '../package.json' appPromise.then((app) => { - app.listen(configuration.sasJsPort, () => { + const sasJsPort = process.env.PORT ?? 5000 + app.listen(sasJsPort, () => { console.log( - `⚡️[server]: Server is running at http://localhost:${configuration.sasJsPort}` + `⚡️[server]: Server is running at http://localhost:${sasJsPort}` ) }) }) diff --git a/api/src/utils/file.ts b/api/src/utils/file.ts index 1745845..14c25bb 100644 --- a/api/src/utils/file.ts +++ b/api/src/utils/file.ts @@ -2,7 +2,7 @@ import path from 'path' import { getRealPath } from '@sasjs/utils' export const getWebBuildFolderPath = () => - getRealPath(path.join(__dirname, '..', '..', '..', 'web', 'build')) + path.join(__dirname, '..', '..', '..', 'web', 'build') export const getTmpFolderPath = () => process.driveLoc ?? getRealPath(path.join(process.cwd(), 'tmp')) diff --git a/docker-compose.yml b/docker-compose.yml index 4d2088c..7964737 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,6 +5,9 @@ services: image: sasjs_server_api build: ./api environment: + MODE: server + CORS: enable + PORT: 5000 DB_CONNECT: mongodb://mongodb:27017/sasjs ports: - 5000:5000 diff --git a/web/.dockerignore b/web/.dockerignore index 6fcffe6..56280d7 100644 --- a/web/.dockerignore +++ b/web/.dockerignore @@ -1,3 +1,3 @@ build node_modules -Dockerfile \ No newline at end of file +Dockerfile