-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tslua-http): fix server hanging, add example app with hot reloading
- Loading branch information
🐸
committed
Nov 29, 2023
1 parent
9429e0f
commit 410c4b6
Showing
7 changed files
with
365 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} | ||
} |
Oops, something went wrong.