Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: updated readme #30

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ Minimum TypeScript compiler options:
An example app:

```tsx
import { MageApp, StatusCode, useSecurityHeaders } from "@mage/server";
import {
MageApp,
StatusCode,
useSecurityHeaders,
useServeFiles,
} from "@mage/server";

const app = new MageApp();

Expand All @@ -53,6 +58,8 @@ app.get("/render", async (context) => {
);
});

app.get("/public/*", useServeFiles({ directory: "./public" }));

app.run({
port: 8000,
onListen({ hostname, port }) {
Expand Down Expand Up @@ -129,7 +136,7 @@ A collection of prebuilt middleware is available to use.
| `useNotFound` | Responds with 404, ignores preflight (OPTIONS) requests |
| `useOptions` | Responds to preflight (OPTIONS) requests |
| `useSecurityHeaders` | Adds recommended security headers to the response |
| `serveFiles` | Serve files from a durectory based on the wildcard on context |
| `useServeFiles` | Serve files from a durectory based on the wildcard on context |

## Context

Expand Down Expand Up @@ -229,6 +236,16 @@ await context.rewrite("/new-location");
await context.rewrite("https://example.com");
```

#### `serveFile`

Serve a file from the file system.

```tsx
await context.serveFile("path/to/file");
```

####

### Cookies

You can read cookies from the request.
Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mage/server",
"version": "0.8.0",
"version": "0.8.1",
"license": "MIT",
"exports": "./mod.ts",
"tasks": {
Expand Down