Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCatalin Mititiuc <webdevcat@proton.me>2024-06-01 17:50:58 -0700
committerCatalin Mititiuc <webdevcat@proton.me>2024-06-01 17:50:58 -0700
commit163e3a9de59f5d6a8df38fa32a1e7dc4db1ad024 (patch)
tree8ae679d3059d8ee8c69a3d45994bc74e4388f76b /server.cjs
parente8fae51b32b6ebc4ec4e16338467b7fcc41edd11 (diff)
Fix/refactor tests
Diffstat (limited to 'server.cjs')
-rw-r--r--server.cjs49
1 files changed, 42 insertions, 7 deletions
diff --git a/server.cjs b/server.cjs
index a4a5cb0..5e16003 100644
--- a/server.cjs
+++ b/server.cjs
@@ -1,5 +1,24 @@
const { createServer } = require('esbuild-server');
const path = require('node:path');
+const fs = require('node:fs');
+const { IncomingMessage } = require('node:http');
+
+class Request extends IncomingMessage {
+ constructor(socket) {
+ super(socket);
+ }
+
+ get url() {
+ console.log('getter called', this._url);
+ return this._url;
+ }
+
+ set url(val) {
+ console.log('setter called', val);
+ this._url = val;
+ }
+}
+
const resolveImportedSvg = {
name: 'resolveImportedSvg',
@@ -12,21 +31,36 @@ const resolveImportedSvg = {
}
}
+const resolveSvgImports = {
+ name: 'resolveSvgImports',
+ setup(build) {
+ build.onStart(() => {
+ fs.rmSync(path.resolve(build.initialOptions.outdir), { recursive: true, force: true });
+ });
+
+ build.onResolve({ filter: /\.svg$/ }, args => {
+ return {
+ path: path.resolve('public', args.path),
+ };
+ });
+ }
+}
+
const server = createServer(
{
bundle: true,
define: {
'env': `"${process.env.NODE_ENV || 'dev'}"`,
},
- entryPoints: ['src/*.js'],
- ...(process.env.NODE_ENV !== 'test') && {
- outdir: 'build'
- },
- plugins: [resolveImportedSvg],
+ entryPoints: ['src/index.js', 'src/soldier_record_block.js', 'src/map.js'],
+ outdir: 'build',
+ // ...(process.env.NODE_ENV !== 'test') && {
+ // outdir: 'build'
+ // },
+ plugins: [resolveSvgImports],
loader: {
'.svg': 'file'
},
- metafile: true,
assetNames: 'assets/images/[name]-[hash]',
},
{
@@ -34,7 +68,8 @@ const server = createServer(
...(process.env.NODE_ENV === 'test') && {
port: 3005,
injectLiveReload: false,
- watch: false
+ watch: false,
+ // http: { IncomingMessage: Request }
}
}
);