Skip to content

Commit 14e71c5

Browse files
committed
add error messages for ports
1 parent ed790ce commit 14e71c5

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

apps/web/vite.config.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import path from 'path';
22

3+
import { parseNumber } from '@douglasneuroinformatics/libjs';
34
import importMetaEnv from '@import-meta-env/unplugin';
45
import { getReleaseInfo } from '@opendatacapture/release-info';
56
import runtime from '@opendatacapture/vite-plugin-runtime';
@@ -9,6 +10,15 @@ import react from '@vitejs/plugin-react-swc';
910
import { defineConfig } from 'vite';
1011
import viteCompression from 'vite-plugin-compression';
1112

13+
const apiPort = parseNumber(process.env.API_DEV_SERVER_PORT);
14+
const webPort = parseNumber(process.env.WEB_DEV_SERVER_PORT);
15+
16+
if (Number.isNaN(apiPort)) {
17+
throw new Error(`Expected API_DEV_SERVER_PORT to be number, got ${process.env.API_DEV_SERVER_PORT}`);
18+
} else if (Number.isNaN(webPort)) {
19+
throw new Error(`Expected WEB_DEV_SERVER_PORT to be number, got ${process.env.WEB_DEV_SERVER_PORT}`);
20+
}
21+
1222
export default defineConfig({
1323
build: {
1424
chunkSizeWarningLimit: 1000,
@@ -45,13 +55,13 @@ export default defineConfig({
4555
}
4656
},
4757
server: {
48-
port: parseInt(process.env.WEB_DEV_SERVER_PORT ?? '3000'),
58+
port: webPort,
4959
proxy: {
5060
'/api/': {
5161
rewrite: (path) => path.replace(/^\/api/, ''),
5262
target: {
5363
host: 'localhost',
54-
port: parseInt(process.env.API_DEV_SERVER_PORT ?? '5500')
64+
port: apiPort
5565
}
5666
}
5767
}

0 commit comments

Comments
 (0)