Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 3175ae4

Browse files
author
Wenjie Xia
committed
refactor: upate typings
1 parent 351b4dc commit 3175ae4

File tree

6 files changed

+28
-41
lines changed

6 files changed

+28
-41
lines changed

cli.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { listenAndServe, path, ServerRequest, walk } from './deps.ts'
1+
import { listenAndServe, path, walk } from './deps.ts'
22
import { Request } from './server/api.ts'
33
import { getContentType } from './server/mime.ts'
44
import { createHtml } from './server/util.ts'
55
import { existsDirSync, existsFileSync } from './shared/fs.ts'
66
import log from './shared/log.ts'
77
import util from './shared/util.ts'
8+
import { ServerRequest } from './types.ts'
89
import { VERSION } from './version.ts'
910

1011
const commands = {

deps.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ export { exists, existsSync } from 'https://deno.land/[email protected]/fs/exists.ts'
88
export { walk } from 'https://deno.land/[email protected]/fs/walk.ts'
99
export { Sha1 } from 'https://deno.land/[email protected]/hash/sha1.ts'
1010
export { Sha256 } from 'https://deno.land/[email protected]/hash/sha256.ts'
11-
export { listenAndServe, serve, ServerRequest } from 'https://deno.land/[email protected]/http/server.ts'
12-
export type { Response } from 'https://deno.land/[email protected]/http/server.ts'
11+
export { listenAndServe, serve } from 'https://deno.land/[email protected]/http/server.ts'
1312
export * as bufio from 'https://deno.land/[email protected]/io/bufio.ts'
1413
export * as path from 'https://deno.land/[email protected]/path/mod.ts'
1514
export * as ws from 'https://deno.land/[email protected]/ws/mod.ts'

server/api.ts

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { brotli, bufio, gzipEncode, Response, ServerRequest } from '../deps.ts'
1+
import { brotli, bufio, gzipEncode } from '../deps.ts'
22
import log from '../shared/log.ts'
3-
import type { APIRequest, FormDataBody } from '../types.ts'
3+
import type { APIRequest, FormDataBody, ServerRequest, ServerResponse } from '../types.ts'
44
import { multiParser } from './multiparser.ts'
55

66
export class Request implements APIRequest {
@@ -41,18 +41,6 @@ export class Request implements APIRequest {
4141
return this.#req.method
4242
}
4343

44-
get proto(): string {
45-
return this.#req.proto
46-
}
47-
48-
get protoMinor(): number {
49-
return this.#req.protoMinor
50-
}
51-
52-
get protoMajor(): number {
53-
return this.#req.protoMajor
54-
}
55-
5644
get headers(): Headers {
5745
return this.#req.headers
5846
}
@@ -69,26 +57,14 @@ export class Request implements APIRequest {
6957
return this.#req.w
7058
}
7159

72-
get done(): Promise<Error | undefined> {
73-
return this.#req.done
74-
}
75-
76-
get contentLength(): number | null {
77-
return this.#req.contentLength
78-
}
79-
8060
get body(): Deno.Reader {
8161
return this.#req.body
8262
}
8363

84-
async respond(r: Response): Promise<void> {
64+
async respond(r: ServerResponse): Promise<void> {
8565
return this.#req.respond(r)
8666
}
8767

88-
async finalize(): Promise<void> {
89-
return this.#req.finalize()
90-
}
91-
9268
get pathname(): string {
9369
return this.#pathname
9470
}

server/project.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { buildChecksum, initWasm, SWCOptions, TransformOptions, transpileSync } from '../compiler/mod.ts'
2-
import type { AcceptedPlugin, ECMA, ServerRequest } from '../deps.ts'
2+
import type { AcceptedPlugin, ECMA } from '../deps.ts'
33
import { CleanCSS, colors, ensureDir, minify, path, postcss, Sha1, Sha256, walk } from '../deps.ts'
44
import { EventEmitter } from '../framework/core/events.ts'
55
import { getPagePath, RouteModule, Routing } from '../framework/core/routing.ts'
66
import { hashShort, reFullVersion, reHashJs, reHashResolve, reHttp, reLocaleID, reModuleExt, reStyleModuleExt } from '../shared/constants.ts'
77
import { ensureTextFile, existsDirSync, existsFileSync } from '../shared/fs.ts'
88
import log from '../shared/log.ts'
99
import util from '../shared/util.ts'
10-
import type { APIHandler, Config, RouterURL } from '../types.ts'
10+
import type { APIHandler, Config, RouterURL, ServerRequest } from '../types.ts'
1111
import { VERSION } from '../version.ts'
1212
import { Request } from './api.ts'
1313
import type { DependencyDescriptor, ImportMap, Module, RenderResult } from './types.ts'

server/server.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ import { getContentType } from './mime.ts'
88
import { Project } from './project.ts'
99
import { createHtml } from './util.ts'
1010

11+
export class Server {
12+
13+
}
14+
15+
export function createServer(): Server {
16+
return new Server()
17+
}
18+
1119
export async function start(appDir: string, hostname: string, port: number, isDev = false, reload = false) {
1220
const project = new Project(appDir, isDev ? 'development' : 'production', reload)
1321
await project.ready

types.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AcceptedPlugin, bufio, Response } from './deps.ts'
1+
import type { AcceptedPlugin, bufio } from './deps.ts'
22

33
export type LoaderPlugin = {
44
/* `type` defines the plugin type */
@@ -68,23 +68,26 @@ export type APIHandler = {
6868
}
6969

7070
/**
71-
* The raw request object of http request.
71+
* An interface that aligns to the parts of std http srever's `ServerRequest`.
7272
*/
7373
export interface ServerRequest {
7474
readonly url: string
7575
readonly method: string
76-
readonly proto: string
77-
readonly protoMinor: number
78-
readonly protoMajor: number
7976
readonly headers: Headers
8077
readonly conn: Deno.Conn
8178
readonly r: bufio.BufReader
8279
readonly w: bufio.BufWriter
83-
readonly done: Promise<Error | undefined>
84-
readonly contentLength: number | null
8580
readonly body: Deno.Reader
86-
respond(r: Response): Promise<void>
87-
finalize(): Promise<void>
81+
respond(r: ServerResponse): Promise<void>
82+
}
83+
84+
/**
85+
* An interface is compatible with std http srever's `request.respond()`.
86+
*/
87+
export interface ServerResponse {
88+
status?: number
89+
headers?: Headers
90+
body?: Uint8Array | Deno.Reader | string
8891
}
8992

9093
/**

0 commit comments

Comments
 (0)