Comparing version 0.12.3 to 0.12.5
{ | ||
"name": "bunshine", | ||
"version": "0.12.3", | ||
"version": "0.12.5", | ||
"module": "server/server.ts", | ||
"type": "module", | ||
"main": "index.ts", | ||
"scripts": { | ||
"test-watch": "bun test --watch", | ||
"coverage": "bun test --coverage", | ||
"lint": "tsc", | ||
"example": "bun --watch ./examples/server.ts" | ||
@@ -44,2 +46,3 @@ }, | ||
"lru-cache": "10.1.0", | ||
"mime": "^4.0.1", | ||
"ms": "2.1.3", | ||
@@ -46,0 +49,0 @@ "path-to-regexp": "6.2.1" |
@@ -1,7 +0,7 @@ | ||
<img alt="Bunshine Logo" src="https://github.com/kensnyder/bunshine/raw/main/assets/bunshine-logo.png?v=0.12.3" width="200" height="187" /> | ||
<img alt="Bunshine Logo" src="https://github.com/kensnyder/bunshine/raw/main/assets/bunshine-logo.png?v=0.12.5" width="200" height="187" /> | ||
[](https://npmjs.com/package/bunshine) | ||
[](https://www.npmjs.com/package/bunshine?activeTab=dependencies) | ||
 | ||
[](https://opensource.org/licenses/ISC) | ||
[](https://npmjs.com/package/bunshine) | ||
[](https://www.npmjs.com/package/bunshine?activeTab=dependencies) | ||
 | ||
[](https://opensource.org/licenses/ISC) | ||
@@ -966,3 +966,7 @@ # Bunshine | ||
- 🔲 tests for prodLogger | ||
- 🔲 tests for gzip | ||
- 🔲 tests for getMimeType | ||
- 🔲 tests for responseFactories | ||
- ✅ tests for serveFiles | ||
- 🔲 100% test coverage | ||
- 🔲 add flags to bin/serve.ts with commander | ||
@@ -969,0 +973,0 @@ - 🔲 document flags for `bunx bunshine serve` |
@@ -5,2 +5,3 @@ import type { BunFile } from 'bun'; | ||
import path from 'node:path'; | ||
import getMimeType from '../getMimeType/getMimeType.ts'; | ||
import { type FileGzipper } from './FileGzipper.ts'; | ||
@@ -23,3 +24,4 @@ import { GzipCache } from './GzipCache.ts'; | ||
>({ | ||
maxSize: this._gzipper.config!.cache.maxBytes!, | ||
// @ts-expect-error | ||
maxSize: this._gzipper.config.cache.maxBytes, | ||
sizeCalculation: ( | ||
@@ -47,3 +49,4 @@ value: { pathToGzipFile: string; zippedSize: number }, | ||
const pathToGzipFile = path.join( | ||
this._gzipper.config!.cache.path!, | ||
// @ts-expect-error | ||
this._gzipper.config.cache.path, | ||
cacheName | ||
@@ -58,3 +61,3 @@ ); | ||
'Content-Encoding': 'gzip', | ||
'Content-Type': file.type, | ||
'Content-Type': getMimeType(file), | ||
'Content-Length': String(body.length), | ||
@@ -72,3 +75,3 @@ 'Last-Modified': new Date(file.lastModified).toUTCString(), | ||
'Content-Encoding': 'gzip', | ||
'Content-Type': file.type, | ||
'Content-Type': getMimeType(file), | ||
'Content-Length': String(zippedSize), | ||
@@ -75,0 +78,0 @@ 'Last-Modified': new Date(file.lastModified).toUTCString(), |
import { BunFile } from 'bun'; | ||
import getMimeType from '../getMimeType/getMimeType.ts'; | ||
import type { GzipOptions } from '../middleware/serveFiles/serveFiles.ts'; | ||
@@ -35,2 +36,3 @@ import FileCache from './FileCache.ts'; | ||
async fetch(file: BunFile) { | ||
const mimeType = getMimeType(file); | ||
if ( | ||
@@ -41,3 +43,3 @@ // @ts-expect-error | ||
file.size > this.config.maxFileSize || | ||
!this.isAllowedMimeType(file.type) | ||
!this.isAllowedMimeType(mimeType) | ||
) { | ||
@@ -48,3 +50,3 @@ const body = process.versions.bun ? file : await file.arrayBuffer(); | ||
headers: { | ||
'Content-Type': file.type, | ||
'Content-Type': mimeType, | ||
'Content-Length': String(file.size), | ||
@@ -51,0 +53,0 @@ 'Last-Modified': new Date(file.lastModified).toUTCString(), |
import type { BunFile } from 'bun'; | ||
import { LRUCache } from 'lru-cache'; | ||
import getMimeType from '../getMimeType/getMimeType.ts'; | ||
import { type FileGzipper } from './FileGzipper.ts'; | ||
@@ -14,2 +15,3 @@ import { GzipCache } from './GzipCache.ts'; | ||
this._cache = new LRUCache<string, Uint8Array>({ | ||
// @ts-expect-error | ||
maxSize: this._gzipper.config!.cache.maxBytes!, | ||
@@ -34,3 +36,3 @@ sizeCalculation: (value: Uint8Array, key: string) => { | ||
'Content-Encoding': 'gzip', | ||
'Content-Type': file.type, | ||
'Content-Type': getMimeType(file), | ||
'Content-Length': String(body!.length), | ||
@@ -37,0 +39,0 @@ 'Last-Modified': new Date(file.lastModified).toUTCString(), |
import type { BunFile } from 'bun'; | ||
import getMimeType from '../getMimeType/getMimeType.ts'; | ||
import { type FileGzipper } from './FileGzipper.ts'; | ||
@@ -18,3 +19,3 @@ import { GzipCache } from './GzipCache.ts'; | ||
'Content-Encoding': 'gzip', | ||
'Content-Type': file.type, | ||
'Content-Type': getMimeType(file), | ||
'Content-Length': String(body.length), | ||
@@ -21,0 +22,0 @@ 'Last-Modified': new Date(file.lastModified).toUTCString(), |
import type { BunFile } from 'bun'; | ||
import fs from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import getMimeType from '../getMimeType/getMimeType.ts'; | ||
import { type FileGzipper } from './FileGzipper.ts'; | ||
@@ -37,3 +38,6 @@ import { GzipCache } from './GzipCache.ts'; | ||
size += file.size; | ||
if (size > this._gzipper.config!.cache.maxBytes!) { | ||
const maxBytes = this._gzipper.config!.cache | ||
? this._gzipper.config!.cache.maxBytes || -1 | ||
: -1; | ||
if (size > maxBytes) { | ||
break; | ||
@@ -44,3 +48,4 @@ } | ||
const cacheName = `${tildized}.${file.lastModified}.gz`; | ||
const cachePath = path.join(this._gzipper.config!.cache.path!, cacheName); | ||
// @ts-expect-error | ||
const cachePath = path.join(this._gzipper.config.cache.path, cacheName); | ||
await fs.writeFile(cachePath, data); | ||
@@ -60,3 +65,3 @@ this._registry[`${file.name}@${file.lastModified}`] = cachePath; | ||
'Content-Encoding': 'gzip', | ||
'Content-Type': file.type, | ||
'Content-Type': getMimeType(file), | ||
'Content-Length': String(zippedFile.size), | ||
@@ -72,3 +77,3 @@ 'Last-Modified': new Date(file.lastModified).toUTCString(), | ||
headers: { | ||
'Content-Type': file.type, | ||
'Content-Type': getMimeType(file), | ||
'Content-Length': String(file.size), | ||
@@ -75,0 +80,0 @@ 'Last-Modified': new Date(file.lastModified).toUTCString(), |
@@ -359,2 +359,3 @@ import type { Server } from 'bun'; | ||
const formData = await request.formData(); | ||
// @ts-expect-error | ||
const json = JSON.stringify(Object.fromEntries(formData)); | ||
@@ -384,2 +385,3 @@ return new Response(json, { | ||
const formData = await request.formData(); | ||
// @ts-expect-error | ||
const json = JSON.stringify(Object.fromEntries(formData)); | ||
@@ -386,0 +388,0 @@ return new Response(json, { |
@@ -95,3 +95,3 @@ import type { ServeOptions, Server } from 'bun'; | ||
} | ||
listen(portOrOptions: ListenOptions) { | ||
listen(portOrOptions: ListenOptions = {}) { | ||
if (typeof portOrOptions === 'number') { | ||
@@ -98,0 +98,0 @@ portOrOptions = { port: portOrOptions }; |
import { BunFile } from 'bun'; | ||
import path from 'node:path'; | ||
import Context from '../Context/Context.ts'; | ||
import getMimeType from '../getMimeType/getMimeType.ts'; | ||
import { gzipString } from '../gzip/gzip.ts'; | ||
@@ -16,3 +17,2 @@ | ||
let body: string | Uint8Array = JSON.stringify(data); | ||
// @ts-expect-error | ||
init.headers = new Headers(init.headers || {}); | ||
@@ -26,3 +26,2 @@ init.headers.set('Content-type', `application/json; charset=utf-8`); | ||
} | ||
// @ts-expect-error | ||
return new Response(body, init); | ||
@@ -33,3 +32,2 @@ } | ||
return function (this: Context, body: string, init: ResponseInit = {}) { | ||
// @ts-expect-error | ||
init.headers = new Headers(init.headers || {}); | ||
@@ -48,3 +46,2 @@ init.headers.set('Content-type', `${contentType}; charset=utf-8`); | ||
init.headers.set('Content-Length', String(body.length)); | ||
// @ts-expect-error | ||
return new Response(body, init); | ||
@@ -255,3 +252,3 @@ }; | ||
'Content-Length': String(file.size), | ||
'Content-Type': file.type || 'application/octet-stream', | ||
'Content-Type': getMimeType(file), | ||
}, | ||
@@ -258,0 +255,0 @@ status: method === 'HEAD' ? 204 : 200, |
@@ -11,3 +11,4 @@ import type Context from '../../Context/Context'; | ||
| (( | ||
incomingOrigin: string | ||
incomingOrigin: string, | ||
context: Context | ||
) => string | string[] | boolean | undefined | null); | ||
@@ -14,0 +15,0 @@ allowMethods?: string[]; |
@@ -176,3 +176,2 @@ import bunshine from '../../../package.json'; | ||
} else if (value === true) { | ||
// @ts-expect-error | ||
value = defaultValues[name]; | ||
@@ -193,3 +192,3 @@ } | ||
function _getCspHeader(directives: CSPDirectives) { | ||
const items = []; | ||
const items: string[] = []; | ||
for (let [key, originalValue] of Object.entries(directives)) { | ||
@@ -237,3 +236,3 @@ let value: | ||
const final = { ...permissionsPolicyDefaults, ...apis }; | ||
const items = []; | ||
const items: string[] = []; | ||
for (const [name, value] of Object.entries(final)) { | ||
@@ -246,3 +245,3 @@ items.push(`${_dasherize(name)}=(${value.join(' ')})`); | ||
function _getSandboxString(options: SandboxOptions) { | ||
const items = []; | ||
const items: string[] = []; | ||
for (const [name, value] of Object.entries(options)) { | ||
@@ -249,0 +248,0 @@ if (value) { |
@@ -45,3 +45,3 @@ import { match } from 'path-to-regexp'; | ||
) { | ||
const matched = []; | ||
const matched: Array<{ target: any; params: Record<string, string> }> = []; | ||
for (const reg of this.registered) { | ||
@@ -48,0 +48,0 @@ const result = reg.matcher(path); |
@@ -148,10 +148,7 @@ import type { Server, ServerWebSocket } from 'bun'; | ||
try { | ||
// @ts-expect-error | ||
target[eventName]?.(ws, ...args); | ||
} catch (e) { | ||
const error = e as Error; | ||
// @ts-expect-error | ||
if (typeof target?.error === 'function') { | ||
try { | ||
// @ts-expect-error | ||
target.error(ws, eventName, error); | ||
@@ -158,0 +155,0 @@ } catch (e) { |
{ | ||
"include": ["index.ts", "package.json", "src/**/*"], | ||
"exclude": [], | ||
"compilerOptions": { | ||
"include": ["*"], | ||
"lib": ["ESNext"], | ||
"lib": ["ESNext", "DOM"], | ||
"module": "esnext", | ||
@@ -12,5 +13,5 @@ "target": "esnext", | ||
"allowImportingTsExtensions": true, | ||
"noEmit": true, | ||
"composite": true, | ||
"strict": true, | ||
"noEmit": true, | ||
"downlevelIteration": true, | ||
@@ -23,5 +24,5 @@ "skipLibCheck": true, | ||
"types": [ | ||
"bun-types" // add Bun global | ||
"bun-types" | ||
] | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
254391
62
4688
984
4
+ Addedmime@^4.0.1
+ Addedmime@4.0.6(transitive)