Skip to content

Commit

Permalink
feat(tslua-http): fix server hanging, add example app with hot reloading
Browse files Browse the repository at this point in the history
  • Loading branch information
🐸 committed Nov 29, 2023
1 parent 9429e0f commit 410c4b6
Show file tree
Hide file tree
Showing 7 changed files with 365 additions and 31 deletions.
6 changes: 3 additions & 3 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useWorkspaces": true,
"version": "0.7.0"
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useWorkspaces": true,
"version": "0.7.0"
}
203 changes: 203 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions packages/tslua-dcs-testapp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@flying-dice/tslua-dcs-testapp",
"version": "1.0.0",
"description": "Test app for DCS World and tslua-http",
"private": true,
"scripts": {
"build": "rimraf dist && tstl -p tsconfig.tstl.json"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@flying-dice/tslua-base64": "^0.7.0",
"@flying-dice/tslua-dcs-types": "^0.7.0",
"@flying-dice/tslua-http-api": "^0.7.0",
"@flying-dice/tslua-http": "^0.7.0"
},
"devDependencies": {
"@biomejs/biome": "^1.4.0",
"lua-types": "^2.13.1",
"prettier": "^3.1.0",
"rimraf": "^5.0.5",
"typescript": "^5.2.2",
"typescript-to-lua": "^1.22.0",
"vitest": "^0.34.6"
}
}
44 changes: 44 additions & 0 deletions packages/tslua-dcs-testapp/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
_G.print = env.info;

import { HttpServer } from "@flying-dice/tslua-http";

declare global {
// biome-ignore lint/style/useConst: It is re-assigned :/
let functionId: number;
// biome-ignore lint/style/useConst: It is re-assigned :/
let app: HttpServer;
}

if (app) {
env.info("Closing existing app");
app.close();
}

app = new HttpServer("127.0.0.1", 1631, (req, res) => {
res.body = "Hello World!";
res.status = 200;
return res;
});

env.info("Starting app");

if (functionId) {
env.info(`Removing existing function ${functionId}`);
timer.removeFunction(functionId);
}

functionId = timer.scheduleFunction(
() => {
try {
app.acceptNextClient();
} catch (e) {
env.error(`Error accepting client: ${e}`);
}

return (timer.getTime() as number) + 0.1;
},
[],
(timer.getTime() as number) + 0.1,
);

env.info(`Started server loop with functionId ${functionId}`);
13 changes: 13 additions & 0 deletions packages/tslua-dcs-testapp/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "ES6",
"lib": ["ES6"],
"moduleResolution": "Node",
"types": ["lua-types/5.1", "@flying-dice/tslua-dcs-types"],
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"outDir": "dist",
"resolveJsonModule": true
}
}
10 changes: 10 additions & 0 deletions packages/tslua-dcs-testapp/tsconfig.tstl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "https://raw.githubusercontent.com/TypeScriptToLua/TypeScriptToLua/master/tsconfig-schema.json",
"extends": "./tsconfig.json",
"tstl": {
"sourceMapTraceback": true,
"luaBundleEntry": "src/index.ts",
"luaBundle": "tslua-testapp.lua",
"noResolvePaths": ["socket"]
}
}
Loading

0 comments on commit 410c4b6

Please sign in to comment.