Skip to content

Commit 8310ac7

Browse files
committed
New web server
1 parent 3c1caf4 commit 8310ac7

File tree

12 files changed

+504
-68
lines changed

12 files changed

+504
-68
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
zoom-platform.sh
22
innoextract*
3-
/www/out
3+
/www/out
4+
www/.env

.vscode/settings.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"deno.enable": true,
3+
"deno.lint": true,
4+
"deno.unstable": true,
5+
"editor.formatOnSave": true,
6+
"deno.enablePaths":[
7+
"./www"
8+
],
9+
"[typescript]": {
10+
"editor.defaultFormatter": "denoland.vscode-deno"
11+
}
12+
}

start-www.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
cd "www" || exit
3+
mkdir -p "dist"
4+
wget -O "dist/zoom-platform.sh" "https://github.com/ZOOM-Platform/zoom-platform.sh/releases/latest/download/zoom-platform.sh"

www/README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# zoom-platform.sh website
2-
no frameworks, no fancy bundlers, just a towering html monolith
2+
Deno server only required if you want to be able to serve specific versions of the script.
33

44
## Deploying
55
1. Clone this repo
6-
2. `cd www && build.sh` (All this does is download the latest release .sh and copy everything to `out`)
7-
3. Serve `www/out/`
6+
2. `./dist.sh`
7+
3. `./start-www.sh` (saves latest stable script to www/dist)
8+
4. `deno task start` (optional)
9+
5. Serve `www/dist`
810

911
We can't use GitHub/CF Pages cause they force SSL. Server is running Nginx with a simple config:
1012
```nginx
@@ -17,7 +19,11 @@ server {
1719
server_name zoom-platform.sh;
1820
1921
location / {
20-
try_files $uri $uri/ $uri.html /index.html;
22+
try_files $uri $uri/ @proxy /index.html;
23+
}
24+
25+
location @proxy {
26+
proxy_pass http://0.0.0.0:23412;
2127
}
2228
}
2329
```

www/build.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

www/deno.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"compilerOptions": {
3+
"allowJs": true,
4+
"lib": ["deno.window"],
5+
"strict": true
6+
},
7+
"lint": {
8+
"include": ["server.ts"],
9+
"rules": {
10+
"tags": ["recommended"],
11+
"include": ["ban-untagged-todo"],
12+
"exclude": ["no-unused-vars"]
13+
}
14+
},
15+
"fmt": {
16+
"useTabs": false,
17+
"lineWidth": 80,
18+
"indentWidth": 2,
19+
"semiColons": false,
20+
"singleQuote": true,
21+
"proseWrap": "always",
22+
"include": ["server.ts"]
23+
},
24+
"tasks": {
25+
"start": "deno run --allow-read='./','../zoom-platform.sh',$(which deno) --allow-env --allow-run=git,sh --allow-sys=uid,gid --allow-net server.ts",
26+
"dev": "deno run --allow-read='./','../zoom-platform.sh',$(which deno) --allow-env --allow-run=git,sh --allow-sys=uid,gid --allow-net --watch server.ts"
27+
},
28+
"exclude": ["dist/"]
29+
}

www/deno.lock

Lines changed: 119 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

www/server.ts

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import { Hono } from 'jsr:@hono/hono'
2+
import { crypto } from 'jsr:@std/crypto'
3+
import { decodeHex } from 'jsr:@std/encoding/hex'
4+
import { load } from 'jsr:@std/dotenv'
5+
import { simpleGit } from 'https://esm.sh/[email protected]'
6+
7+
const env = await load()
8+
9+
const buildScriptFrom = async (src: string, hash: string = '') => {
10+
const command = new Deno.Command('sh', {
11+
args: [
12+
'../build.sh',
13+
src,
14+
'innoextract-upx',
15+
hash,
16+
],
17+
})
18+
const { code, stdout } = await command.output()
19+
if (code === 0) {
20+
return new TextDecoder().decode(stdout)
21+
}
22+
return `#!/bin/sh\nprintf "error building script from ${hash}\\n"`
23+
}
24+
25+
const ac = new AbortController()
26+
const app = new Hono()
27+
28+
app.get('/:commithash{[a-f\\d]{7,40}}', async (ctx) => {
29+
const commithash = ctx.req.param('commithash')
30+
try {
31+
const srcFile = await simpleGit().show(`${commithash}:src.sh`)
32+
const gittag = await simpleGit().tag(['--points-at', commithash])
33+
let forcedVersion = gittag.trim()
34+
if (!forcedVersion) forcedVersion = commithash.substring(0, 7)
35+
const script = await buildScriptFrom(srcFile, forcedVersion)
36+
return ctx.text(script)
37+
} catch (err) {
38+
//
39+
}
40+
return ctx.text(commithash, 404)
41+
})
42+
43+
// latest commit is always built in parent
44+
app.get('/latest', async (ctx) => {
45+
return ctx.text(await Deno.readTextFile('../zoom-platform.sh'))
46+
})
47+
48+
// hook to kill server, should only trigger on push or release
49+
// when the server restarts the latest changes will get pulled
50+
app.post('/gh-hook', async (ctx) => {
51+
const rawBody = await ctx.req.raw.text()
52+
const sigHeader = ctx.req.header('X-Hub-Signature-256')
53+
if (!rawBody || !sigHeader) return ctx.body(null, 401)
54+
55+
const parts = sigHeader.split('=')
56+
const sigHex = parts[1]
57+
58+
try {
59+
const te = new TextEncoder()
60+
const key = await crypto.subtle.importKey(
61+
'raw',
62+
te.encode(env['GH_HOOK_SECRET']),
63+
{ name: 'HMAC', hash: { name: 'SHA-256' } },
64+
false,
65+
['sign', 'verify'],
66+
)
67+
const data = te.encode(rawBody)
68+
const verified = await crypto.subtle.verify(
69+
'HMAC',
70+
key,
71+
decodeHex(sigHex),
72+
data,
73+
)
74+
if (!verified) {
75+
return ctx.status(401)
76+
}
77+
} catch (error) {
78+
return ctx.status(401)
79+
}
80+
81+
setTimeout(() => {
82+
ac.abort()
83+
}, 1000)
84+
85+
return ctx.text('bye', 200)
86+
})
87+
88+
const server = Deno.serve({
89+
port: 23412,
90+
hostname: '0.0.0.0',
91+
signal: ac.signal,
92+
}, app.fetch)
93+
94+
server.finished.then(() => {
95+
console.log('server is kill')
96+
})
-8.08 KB
Binary file not shown.
-113 KB
Binary file not shown.

0 commit comments

Comments
 (0)