https://github.com/ije/assets
Create http response with static asset files.
https://github.com/ije/assets
Last synced: about 1 year ago
JSON representation
Create http response with static asset files.
- Host: GitHub
- URL: https://github.com/ije/assets
- Owner: ije
- Created: 2023-04-11T03:35:33.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-03-18T04:09:10.000Z (about 2 years ago)
- Last Synced: 2025-03-31T04:31:42.484Z (about 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 8.79 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Assets
Create http response with static asset files.
## Usage
To use **Assets**, create a `server.tsx` file like this:
```ts
import assets from "https://deno.land/x/assets@0.0.4/mod.ts";
Deno.serve((req) =>
assets(
req,
{
root: "./public",
ignore: ["/private"],
transform: /\.(jsx|tsx?)$/,
transformOptions: {
jsxFactory: "h",
jsxFragmentFactory: "Fragment",
},
},
() => new Response("Not found", { status: 404 }),
)
);
```
**Run the server**:
```bash
deno run --allow-net --allow-read server.tsx
```
## Options
- `root` - The root directory to serve static assets from. Defaults to `./`.
- `ignore` - An array of paths to ignore. Defaults to `[]`.
- `transform` - A regular expression to match files that should be transformed,
or set it to `true` to transform all files. Defaults to `false`.
- `transformOptions` - Options to pass to
[`esbuild.transform`](https://esbuild.github.io/api/#transform) for
transforming files. Defaults to `{}`.
## Extend Asset Types
By default, **Assets** supports types defined in
[`media_type.ts`](./media_type.ts), you can extend it use `registerType` function:
```ts
import { registerType } from "https://deno.land/x/assets@0.0.4/mod.ts";
registerType("apk", "application/vnd.android.package-archive");
```