From e8f339c58c5bd980a8c1e38c0a6ea0bc56818973 Mon Sep 17 00:00:00 2001 From: KeziaWahome Date: Thu, 4 Jan 2024 00:40:21 +0200 Subject: [PATCH] update:adding azure production script --- api/package.json | 1 + api/server.js | 18 +++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/api/package.json b/api/package.json index 59943c7..ddf25d9 100644 --- a/api/package.json +++ b/api/package.json @@ -14,6 +14,7 @@ }, "scripts": { "generate-swagger": "swagger-jsdoc -d swagger.js -o swagger.json" + }, "devDependencies": {} } diff --git a/api/server.js b/api/server.js index 2d3a495..b3328f9 100644 --- a/api/server.js +++ b/api/server.js @@ -181,8 +181,8 @@ import Comment from "./models/Comment.js"; import VotingRoutes from "./VotingRoutes.js"; import swaggerUi from 'swagger-ui-express'; import { swaggerSpec } from './swagger.js'; +import path from 'path'; -const path = require ('path') const secret = 'secret123'; const app = express(); @@ -194,15 +194,15 @@ app.use(cors({ credentials: true, })); -// // adding production script for deployment -// app.use(express.static("./client/build")); -// app.get("*",(req,res) => { -// res.sendFile(path.resolve(__dirname , "client","build" , "index.html")) -// }) -// production scrpit on -// Serve static files from the "client/build" directory -app.use(express.static(path.resolve(__dirname, 'client', 'build'))); + +// production scrpit one +// For serving static files from the 'client/build' directory +const currentModuleURL = new URL(import.meta.url); +const currentModuleDir = path.dirname(currentModuleURL.pathname); + +app.use(express.static(path.resolve(currentModuleDir, 'client', 'build'))); + app.use(VotingRoutes);