WIP: modify dev server to use as test server, also
This commit is contained in:
parent
c424c1fef2
commit
2dfd5cdac3
@ -22,6 +22,7 @@ const mime = {
|
|||||||
'.jpg': 'image/jpeg',
|
'.jpg': 'image/jpeg',
|
||||||
'.css': 'text/css; charset=utf-8',
|
'.css': 'text/css; charset=utf-8',
|
||||||
'.html': 'text/html; charset=utf-8',
|
'.html': 'text/html; charset=utf-8',
|
||||||
|
'.js': 'text/javascript; charset=utf-8',
|
||||||
};
|
};
|
||||||
|
|
||||||
function createServerSentEventHandler() {
|
function createServerSentEventHandler() {
|
||||||
@ -220,7 +221,7 @@ const externalSvgToInternal = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const ctx = await esbuild.context({
|
const buildOptions = {
|
||||||
entryPoints: ['src/index.js', 'src/soldier_record_block.js', 'src/map.js'],
|
entryPoints: ['src/index.js', 'src/soldier_record_block.js', 'src/map.js'],
|
||||||
bundle: true,
|
bundle: true,
|
||||||
outdir: 'build',
|
outdir: 'build',
|
||||||
@ -233,8 +234,36 @@ const ctx = await esbuild.context({
|
|||||||
'.svg': 'file'
|
'.svg': 'file'
|
||||||
},
|
},
|
||||||
assetNames: 'assets/images/[name]-[hash]',
|
assetNames: 'assets/images/[name]-[hash]',
|
||||||
|
};
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV === 'test') {
|
||||||
|
http.createServer((req, res) => {
|
||||||
|
const filename = req.url && req.url !== '/' ? req.url : 'index.html';
|
||||||
|
const filepath = ['public', 'build'].map(dir => path.join(__dirname, dir, filename)).find(fp => fs.existsSync(fp));
|
||||||
|
|
||||||
|
if (filepath) {
|
||||||
|
const readStream = fs.createReadStream(filepath, { autoClose: true });
|
||||||
|
|
||||||
|
readStream.on('ready', () => {
|
||||||
|
const type = mime[path.parse(filepath).ext] || 'text/plain';
|
||||||
|
res.writeHead(200, { 'content-type': type });
|
||||||
|
readStream.pipe(res, { end: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
readStream.on('error', err => {
|
||||||
|
res.writeHead(500, err.name);
|
||||||
|
res.end(JSON.stringify(err));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
res.writeHead(404, { 'content-type': 'text/plain' });
|
||||||
|
res.end("Not found");
|
||||||
|
}
|
||||||
|
}).listen(3005, () => {
|
||||||
|
console.log('test server is online');
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
buildOptions.define = { 'window.IS_DEV': 'true' };
|
||||||
|
const ctx = await esbuild.context(buildOptions);
|
||||||
await ctx.watch();
|
await ctx.watch();
|
||||||
|
|
||||||
const { host, port } = await ctx.serve({
|
const { host, port } = await ctx.serve({
|
||||||
@ -294,5 +323,6 @@ http.createServer((req, res) => {
|
|||||||
}).listen(8080, (e) => {
|
}).listen(8080, (e) => {
|
||||||
console.log('server is online', e);
|
console.log('server is online', e);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// console.log(`${process.env.NODE_ENV === 'test' ? 'Test' : 'Development'} server running at ${server.url}`);
|
// console.log(`${process.env.NODE_ENV === 'test' ? 'Test' : 'Development'} server running at ${server.url}`);
|
||||||
|
@ -3,11 +3,6 @@
|
|||||||
<head>
|
<head>
|
||||||
<title>Infantry Combat Solo Basic</title>
|
<title>Infantry Combat Solo Basic</title>
|
||||||
<link rel="stylesheet" href="assets/css/style.css">
|
<link rel="stylesheet" href="assets/css/style.css">
|
||||||
<script>
|
|
||||||
const source = new EventSource('/esbuild');
|
|
||||||
source.addEventListener('change', () => location.reload());
|
|
||||||
// source.addEventListener('message', (e) => console.log(e));
|
|
||||||
</script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<template id="damage-block">
|
<template id="damage-block">
|
||||||
|
@ -7,6 +7,12 @@ import { scenarios } from './modules/scenarios.js';
|
|||||||
|
|
||||||
globalThis.svgns = 'http://www.w3.org/2000/svg';
|
globalThis.svgns = 'http://www.w3.org/2000/svg';
|
||||||
|
|
||||||
|
if (window.IS_DEV) {
|
||||||
|
const source = new EventSource('/esbuild');
|
||||||
|
source.addEventListener('change', () => location.reload());
|
||||||
|
// source.addEventListener('message', (e) => console.log(e));
|
||||||
|
}
|
||||||
|
|
||||||
const mapPlaceholder = document.querySelector('.map-placeholder'),
|
const mapPlaceholder = document.querySelector('.map-placeholder'),
|
||||||
distanceOutput = document.getElementById('status'),
|
distanceOutput = document.getElementById('status'),
|
||||||
proneToggle = document.getElementById('toggle-prone-counter'),
|
proneToggle = document.getElementById('toggle-prone-counter'),
|
||||||
|
@ -2,7 +2,7 @@ console.log('\nSpawning server process...');
|
|||||||
const { spawn } = require('child_process');
|
const { spawn } = require('child_process');
|
||||||
|
|
||||||
module.exports = async function (globalConfig, projectConfig) {
|
module.exports = async function (globalConfig, projectConfig) {
|
||||||
const child = spawn('node', ['server.cjs']);
|
const child = spawn('node', ['esbuild-server.mjs']);
|
||||||
|
|
||||||
child.stdout.on('data', (data) => {
|
child.stdout.on('data', (data) => {
|
||||||
console.log(`${data}`);
|
console.log(`${data}`);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user