From 63588e0500c4b126621c326a8fcb8a5fc7dcd302 Mon Sep 17 00:00:00 2001 From: Guillaume Dorce Date: Fri, 28 Oct 2022 10:29:12 +0200 Subject: [PATCH] fix express static folder --- src/index.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index b7967e4..a36b2b6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,6 +5,7 @@ import { config as envConfig } from 'dotenv'; import { deleteExpiredTokens } from '@/controller/AuthController'; import ms from 'ms'; import path from 'path'; +import fs from 'fs'; envConfig(); @@ -42,7 +43,13 @@ app.use(json({ limit: '50mb' })); app.use(urlencoded({ extended: true, limit: '50mb' })); app.use(express.static(path.join(__dirname, '../public'))); -app.use(express.static(path.join(__dirname, '../client/dist'))); + +// check if folder dist-vite exists +if (fs.existsSync(path.join(__dirname, '../client/dist-vite'))) { + app.use(express.static(path.join(__dirname, '../client/dist-vite'))); +} else { + app.use(express.static(path.join(__dirname, '../client/dist'))); +} app.use('/api', api);