First off, I just wanted to say I could not choose the correct category because it kept crashing my internet browser. (IDK why)
The newest code in serve.js:
const requestHandler = (request, response) => {
//console.log(request.url);
const requestUrl = new URL(request.url, base);
const requestPath = requestUrl.pathname;
let requestFile = path.normalize(`${dir}/${requestPath}`);
if (!requestFile.startsWith(dir)) {
response.statusCode = 400;
response.end();
return;
} else if (requestFile.endsWith(path.sep)) {
requestFile += 'index.html';
} else if (requestFile.endsWith('mygame.js')) {
const gameDir = path.basename(path.dirname(requestFile));
const mygame = child_process.execSync('node mygamegenerator.js ${gameDir}', {encoding: 'utf8'});
fs.writeFileSync(`${dir}/web/${gameDir}/mygame.js`, mygame, 'utf8');
}
This is the newest serve.js above. It is broken in that it is not replacing ${gameDir} with the actual directory. It was literally calling web/${gameDir}/scenes/startup.txt, where ${gameDir} is obviously not the name of the directory. The old version of serve.js (that I have from around last december) is this:
const requestHandler = (request, response) => {
//console.log(request.url);
const requestUrl = new URL(request.url, base);
const requestPath = requestUrl.pathname;
let requestFile = path.normalize(`${dir}/${requestPath}`);
if (!requestFile.startsWith(dir)) {
response.statusCode = 400;
response.end();
return;
} else if (requestFile.endsWith(path.sep)) {
requestFile += 'index.html';
}
I found this error because my new game was not working when I ran the server to test it. Basically it looks like the extra else if statement was breaking it.
Thank you ChatGPT for finding the error ![]()
I just wanted to post this so this could be fixed for future people.
BTW this was fixed just by replacing the new serve.js with the old one.
