Skip to content

Commit 124f979

Browse files
authored
Merge pull request #79 from cirex-web/fix/content-type-headers
2 parents 62aea0c + da80c86 commit 124f979

19 files changed

Lines changed: 986 additions & 389 deletions

.github/workflows/test.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
test:
9+
name: Test code
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
16+
- name: Setup bun
17+
uses: oven-sh/setup-bun@v1
18+
with:
19+
bun-version: latest
20+
21+
- name: Install packages
22+
run: bun install
23+
24+
- name: Test
25+
run: bun run test

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ node_modules
44
.pnpm-debug.log
55
dist
66

7-
build
7+
build
8+
cmueats-build

bench/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};

bench/index.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Bench } from 'tinybench'
2+
import { Elysia } from 'elysia'
3+
import { staticPlugin } from '../src'
4+
import { req } from '../test/utils'
5+
6+
const bench = new Bench({ time: 10000 })
7+
8+
const app = new Elysia().use(
9+
staticPlugin({
10+
assets: 'public',
11+
prefix: 'public',
12+
indexHTML: true,
13+
bunFullstack: false,
14+
alwaysStatic: true
15+
})
16+
)
17+
await app.modules
18+
console.log(app.routes)
19+
bench.add('route caching', async () => {
20+
const htmlPaths = [
21+
'/public/html',
22+
'/public/html/',
23+
'/public/html/index.html',
24+
'/public/html/index.html/'
25+
]
26+
for (const path of htmlPaths) {
27+
const res = await app.handle(req(path))
28+
await (await res.blob()).text()
29+
}
30+
})
31+
32+
await bench.run()
33+
console.table(bench.table())

bun.lock

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

example/index.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
import { Elysia } from 'elysia'
22
import { staticPlugin } from '../src/index'
3-
4-
const app = new Elysia()
5-
.use(
6-
await staticPlugin({
7-
prefix: '/',
8-
bundleHTML: false
9-
})
10-
)
11-
.listen(3000)
12-
13-
console.log(app.routes)
14-
15-
await app.modules
3+
import { node } from '@elysiajs/node'
4+
import { isBun } from '../src/utils'
5+
;(async () => {
6+
const app = new Elysia(isBun ? {} : { adapter: node() })
7+
.use(
8+
await staticPlugin({
9+
prefix: 'hi',
10+
assets: 'public',
11+
alwaysStatic: true,
12+
bunFullstack: true,
13+
decodeURI: false,
14+
etag: false
15+
// staticLimit: 1
16+
})
17+
)
18+
.listen(3005)
19+
await app.modules
20+
console.log(app.routes)
21+
})() // no top-level awaits allowed for cjs (error triggered by `bun dev:node`) (idk how to fix this)

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"license": "MIT",
66
"scripts": {
77
"dev": "bun run --watch example/index.ts",
8-
"test": "bun test && npm run test:node",
8+
"dev:node": "tsx watch example/index.ts",
9+
"bench": "bun run bench/index.ts",
10+
"test": "bun run build && bun test && vitest run && npm run test:node",
911
"test:node": "npm install --prefix ./test/node/cjs/ && npm install --prefix ./test/node/esm/ && node ./test/node/cjs/index.js && node ./test/node/esm/index.js",
1012
"build": "bun build.ts",
1113
"release": "npm run build && npm run test && npm publish --access public"
@@ -48,6 +50,7 @@
4850
}
4951
},
5052
"devDependencies": {
53+
"@elysiajs/node": "^1.4.5",
5154
"@types/bun": "^1.3.13",
5255
"@types/fast-decode-uri-component": "^1.0.0",
5356
"@types/node": "^24.12.2",
@@ -56,10 +59,13 @@
5659
"esbuild-fix-imports-plugin": "^1.0.23",
5760
"eslint": "9.6.0",
5861
"fast-decode-uri-component": "^1.0.1",
62+
"tinybench": "^6.0.1",
5963
"tsup": "^8.5.1",
60-
"typescript": "^5.9.3"
64+
"tsx": "^4.21.0",
65+
"typescript": "^5.9.3",
66+
"vitest": "^4.1.5"
6167
},
6268
"peerDependencies": {
6369
"elysia": ">= 1.4.0"
6470
}
65-
}
71+
}

public/MGICALCURE_LOVE_SHOT.mp3

3.09 MB
Binary file not shown.

public/html/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html>
33
<head>
44
<title>Home!</title>

public/js/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("hi")

0 commit comments

Comments
 (0)