Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCatalin Mititiuc <webdevcat@proton.me>2024-04-18 10:01:26 -0700
committerCatalin Mititiuc <webdevcat@proton.me>2024-04-18 10:05:21 -0700
commit8e74cef4a5b63ab14e47d8d698f804745c0c4ea6 (patch)
tree6fee17cb5c152ae584d4e81a7c941ee9d08588e9 /dev-server.cjs
parent23967fe2f5ae9fb6d6c8a2cbc29845531f7acece (diff)
Run server on different port when running tests
Diffstat (limited to 'dev-server.cjs')
-rw-r--r--dev-server.cjs33
1 files changed, 21 insertions, 12 deletions
diff --git a/dev-server.cjs b/dev-server.cjs
index fc4da91..13b517a 100644
--- a/dev-server.cjs
+++ b/dev-server.cjs
@@ -1,13 +1,22 @@
-console.log('Starting server.');
+const { createServer } = require('esbuild-server');
+const server = createServer(
+ {
+ bundle: true,
+ entryPoints: ['src/index.js'],
+ },
+ {
+ static: 'public',
+ ...(process.argv.slice(2).includes('--test')) && { port: 3005 }
+ }
+);
-require('esbuild-server')
- .createServer(
- {
- bundle: true,
- entryPoints: ['src/index.js'],
- },
- {
- static: 'public'
- }
- )
- .start();
+const buildStart = Date.now();
+server
+ .start()
+ .then(() => {
+ console.log(`Build completed in ${Date.now() - buildStart}ms`);
+ })
+ .catch(() => {
+ console.error('Build failed');
+ });
+console.log(`Development server running at ${server.url}`);