@wiajs/static
v1.4.12
Published
Plugin for Elysia for serving static folder
Readme
@wiajs/static
Plugin for elysia for serving static folder.
Installation
bun add @wiajs/static使用说明
默认(推荐):动态通配符,生产环境也支持增/改/新目录的即时生效:
app.use(staticPlugin({
assets: ['public', 'assets'], // 支持数组
prefix: '/', // 根路径服务
preCompressed: true, // 若你的构建产出 .br/.gz
redirect: true, // 目录无斜杠时 301 补齐
headers: { 'X-Powered-By': 'elysia-static' }
}))预注册(小目录、高性能):
app.use(staticPlugin({
assets: 'public',
prefix: '/',
alwaysStatic: true, // 预注册
staticLimit: 2000, // 若超限会自动回退为动态
extension: true,
indexHTML: true
}))app.use(staticPlugin({
assets: ['public', 'assets'],
prefix: '/', // 根路径服务
preCompressed: true,
enableHEAD: true, // 需要 HEAD 就开;只用 GET 也可
// 生产策略
prewarmEnable: process.env.NODE_ENV === 'production',
prewarmMaxFiles: 300, // 预热最多 300 个
cacheMaxEntries: 1000, // 缓存上限
cacheOvershoot: 200 // 超出 5200 时清理回 5000
}))Example
import { Elysia } from 'elysia'
import { staticPlugin } from '@wiajs/static'
const app = new Elysia()
.use(staticPlugin())
.listen(8080)Config
Below is an available config for a static plugin.
assets
@default "public"
Asset path to expose as a public path
prefix
@default '/public'
Path prefix to create a virtual mount path for the static directory
staticLimit
@defualt 1024
If total files exceed this number, the file will be handled via wildcard instead of the static route to reduce memory usage
alwaysStatic
@default boolean
If set to true, the file will always use a static path instead
