-
Notifications
You must be signed in to change notification settings - Fork 235
/
mod.ts
160 lines (157 loc) · 3.93 KB
/
mod.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// Copyright 2018-2024 the oak authors. All rights reserved. MIT license.
/**
* A middleware framework for handling HTTP with [Deno CLI](https://deno.land),
* [Deno Deploy](https://deno.com/deploy),
* [Cloudflare Workers](https://workers.cloudflare.com/),
* [Node.js](https://nodejs.org/), and [Bun](https://bun.sh/).
*
* oak is inspired by [koa](https://koajs.com/).
*
* ## Example server
*
* A minimal router server which responds with content on `/`.
*
* ### Deno CLI and Deno Deploy
*
* ```ts
* import { Application } from "jsr:@oak/oak/application";
* import { Router } from "jsr:@oak/oak/router";
*
* const router = new Router();
* router.get("/", (ctx) => {
* ctx.response.body = `<!DOCTYPE html>
* <html>
* <head><title>Hello oak!</title><head>
* <body>
* <h1>Hello oak!</h1>
* </body>
* </html>
* `;
* });
*
* const app = new Application();
* app.use(router.routes());
* app.use(router.allowedMethods());
*
* app.listen({ port: 8080 });
* ```
*
* ### Node.js and Bun
*
* You will have to install the package and then:
*
* ```ts
* import { Application } from "@oak/oak/application";
* import { Router } from "@oak/oak/router";
*
* const router = new Router();
* router.get("/", (ctx) => {
* ctx.response.body = `<!DOCTYPE html>
* <html>
* <head><title>Hello oak!</title><head>
* <body>
* <h1>Hello oak!</h1>
* </body>
* </html>
* `;
* });
*
* const app = new Application();
* app.use(router.routes());
* app.use(router.allowedMethods());
*
* app.listen({ port: 8080 });
* ```
*
* ### Cloudflare Workers
*
* You will have to install the package and then:
*
* ```ts
* import { Application } from "@oak/oak/application";
* import { Router } from "@oak/oak/router";
*
* const router = new Router();
* router.get("/", (ctx) => {
* ctx.response.body = `<!DOCTYPE html>
* <html>
* <head><title>Hello oak!</title><head>
* <body>
* <h1>Hello oak!</h1>
* </body>
* </html>
* `;
* });
*
* const app = new Application();
* app.use(router.routes());
* app.use(router.allowedMethods());
*
* export default { fetch: app.fetch };
* ```
*
* @module
*/
export {
Application,
type ApplicationOptions,
type ListenOptions,
type ListenOptionsBase,
type ListenOptionsTls,
type State,
} from "./application.ts";
export type { BodyType } from "./body.ts";
export { Context, type ContextSendOptions } from "./context.ts";
export { Server as HttpServerNative } from "./http_server_native.ts";
export { type NativeRequest } from "./http_server_native_request.ts";
export * as etag from "./middleware/etag.ts";
export { proxy, type ProxyOptions } from "./middleware/proxy.ts";
export {
route,
RouteContext,
serve,
ServeContext,
} from "./middleware/serve.ts";
export {
compose as composeMiddleware,
type Middleware,
type MiddlewareObject,
type MiddlewareOrMiddlewareObject,
type Next,
} from "./middleware.ts";
export { Request } from "./request.ts";
export { REDIRECT_BACK, Response } from "./response.ts";
export {
type Route,
type RouteParams,
Router,
type RouterAllowedMethodsOptions,
type RouterContext,
type RouterMiddleware,
type RouterOptions,
type RouterParamMiddleware,
} from "./router.ts";
export { send, type SendOptions } from "./send.ts";
/** Utilities for making testing oak servers easier. */
export * as testing from "./testing.ts";
export { type ServerConstructor } from "./types.ts";
// Re-exported from `std/http`
export {
createHttpError,
errors as httpErrors,
type ErrorStatus,
HttpError,
type HTTPMethods,
isErrorStatus,
isHttpError,
isRedirectStatus,
type RedirectStatus,
SecureCookieMap as Cookies,
type SecureCookieMapGetOptions as CookiesGetOptions,
type SecureCookieMapSetDeleteOptions as CookiesSetDeleteOptions,
ServerSentEvent,
type ServerSentEventInit,
type ServerSentEventTarget,
Status,
STATUS_TEXT,
} from "./deps.ts";