@fastly/expressly 1.0.0-alpha.1 → 1.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/lib/routing/request/index.d.ts +9 -6
- package/dist/lib/routing/request/index.js +41 -18
- package/dist/lib/routing/router.js +1 -1
- package/package.json +1 -1
- package/dist/lib/routing/middleware.d.ts +0 -10
- package/dist/lib/routing/middleware.js +0 -13
- package/dist/lib/routing/route.d.ts +0 -10
- package/dist/lib/routing/route.js +0 -12
package/README.md
CHANGED
|
@@ -17,11 +17,11 @@ First, head over to [developer.fastly.com](https://developer.fastly.com) to get
|
|
|
17
17
|
Install expressly from the [npm registry](https://www.npmjs.com/package/@fastly/expressly):
|
|
18
18
|
|
|
19
19
|
```shell
|
|
20
|
-
npm i @fastly/expressly
|
|
20
|
+
npm i @fastly/expressly@1.0.0-alpha.4
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
```shell
|
|
24
|
-
yarn add @fastly/expressly
|
|
24
|
+
yarn add @fastly/expressly@1.0.0-alpha.4
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
### Your first expressly app
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
/// <reference types="@fastly/js-compute" />
|
|
2
|
-
import { ECommonObject } from "../common";
|
|
3
2
|
import { CookieMap } from "./cookie-map";
|
|
4
3
|
import { EConfig } from "..";
|
|
5
|
-
export declare class ERequest extends
|
|
4
|
+
export declare class ERequest extends Request {
|
|
6
5
|
private config;
|
|
7
6
|
private event;
|
|
8
7
|
readonly clientInfo: ClientInfo;
|
|
9
8
|
readonly method: string;
|
|
10
9
|
headers: Headers;
|
|
11
|
-
|
|
10
|
+
urlObj: URL;
|
|
12
11
|
query: URLSearchParams;
|
|
13
12
|
params: {
|
|
14
13
|
[key: string]: string;
|
|
@@ -21,7 +20,11 @@ export declare class ERequest extends ECommonObject {
|
|
|
21
20
|
get secure(): boolean;
|
|
22
21
|
get subdomains(): Array<string>;
|
|
23
22
|
get hostname(): string;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
set(headerNameOrObject: string | {
|
|
24
|
+
[key: string]: string;
|
|
25
|
+
}, value?: string): void;
|
|
26
|
+
private appendHeader;
|
|
27
|
+
append(headerNameOrObject: string | {
|
|
28
|
+
[key: string]: string | string[];
|
|
29
|
+
}, value?: string | string[]): void;
|
|
27
30
|
}
|
|
@@ -1,47 +1,70 @@
|
|
|
1
|
-
import { ECommonObject } from "../common";
|
|
2
1
|
import { CookieMap } from "./cookie-map";
|
|
3
|
-
export class ERequest extends
|
|
2
|
+
export class ERequest extends Request {
|
|
4
3
|
constructor(config, event) {
|
|
5
|
-
super();
|
|
4
|
+
super(event.request);
|
|
6
5
|
this.config = config;
|
|
7
6
|
this.event = event;
|
|
8
7
|
this.params = {};
|
|
9
8
|
this.clientInfo = event.client;
|
|
10
|
-
this.
|
|
11
|
-
this.
|
|
12
|
-
this.query = this.url.searchParams;
|
|
13
|
-
this.headers = event.request.headers;
|
|
9
|
+
this.urlObj = new URL(event.request.url);
|
|
10
|
+
this.query = this.urlObj.searchParams;
|
|
14
11
|
// Parse cookies.
|
|
15
12
|
if (this.config.parseCookie) {
|
|
16
13
|
this.cookies = new CookieMap(this.headers);
|
|
17
14
|
}
|
|
18
15
|
}
|
|
19
16
|
// Express-like URL helpers.
|
|
17
|
+
// get url(): string {
|
|
18
|
+
// console.log("custom getter");
|
|
19
|
+
// return this.urlObj.toString();
|
|
20
|
+
// }
|
|
20
21
|
get path() {
|
|
21
|
-
return this.
|
|
22
|
+
return this.urlObj.pathname;
|
|
22
23
|
}
|
|
23
24
|
get ip() {
|
|
24
25
|
return this.clientInfo.address;
|
|
25
26
|
}
|
|
26
27
|
get protocol() {
|
|
27
|
-
return this.
|
|
28
|
+
return this.urlObj.protocol;
|
|
28
29
|
}
|
|
29
30
|
get secure() {
|
|
30
|
-
return this.
|
|
31
|
+
return this.urlObj.protocol === "https";
|
|
31
32
|
}
|
|
32
33
|
get subdomains() {
|
|
33
|
-
return this.
|
|
34
|
+
return this.urlObj.hostname.split(".").slice(0, -2);
|
|
34
35
|
}
|
|
35
36
|
get hostname() {
|
|
36
|
-
return this.
|
|
37
|
+
return this.urlObj.hostname;
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
// Header helpers.
|
|
40
|
+
set(headerNameOrObject, value) {
|
|
41
|
+
if (typeof headerNameOrObject === "string") {
|
|
42
|
+
this.headers.set(headerNameOrObject, value);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
Object.keys(headerNameOrObject).forEach((headerName) => {
|
|
46
|
+
this.headers.set(headerName, headerNameOrObject[headerName]);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
40
49
|
}
|
|
41
|
-
|
|
42
|
-
|
|
50
|
+
appendHeader(headerName, headerValue) {
|
|
51
|
+
if (typeof headerValue === "string") {
|
|
52
|
+
this.headers.append(headerName, headerValue);
|
|
53
|
+
}
|
|
54
|
+
else if (Array.isArray(headerValue)) {
|
|
55
|
+
headerValue.forEach((v) => {
|
|
56
|
+
this.headers.append(headerName, v);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
43
59
|
}
|
|
44
|
-
|
|
45
|
-
|
|
60
|
+
append(headerNameOrObject, value) {
|
|
61
|
+
if (typeof headerNameOrObject === "string") {
|
|
62
|
+
this.appendHeader(headerNameOrObject, value);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
Object.keys(headerNameOrObject).forEach((headerName) => {
|
|
66
|
+
this.appendHeader(headerName, headerNameOrObject[headerName]);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
46
69
|
}
|
|
47
70
|
}
|
|
@@ -140,7 +140,7 @@ export class Router {
|
|
|
140
140
|
pathMatcherCache.set(pattern, match(pattern, { decode: decodeURIComponent }));
|
|
141
141
|
}
|
|
142
142
|
// Match on pathname.
|
|
143
|
-
let { path, params } = pathMatcherCache.get(pattern)(req.
|
|
143
|
+
let { path, params } = pathMatcherCache.get(pattern)(req.urlObj.pathname) || {};
|
|
144
144
|
if (path) {
|
|
145
145
|
if (this.config.extractRequestParameters) {
|
|
146
146
|
req.params = params;
|
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import ERequest from "./request";
|
|
2
|
-
import EResponse from "./response";
|
|
3
|
-
export declare type MiddlewareCallback = (req: ERequest, res: EResponse, next?: () => void) => Promise<any>;
|
|
4
|
-
export declare class Middleware {
|
|
5
|
-
private matchFn;
|
|
6
|
-
private callback;
|
|
7
|
-
constructor(matchFn: Function, callback: MiddlewareCallback);
|
|
8
|
-
check(event: ERequest): 0 | 404 | 405;
|
|
9
|
-
run(req: ERequest, res: EResponse): Promise<any>;
|
|
10
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export class Middleware {
|
|
2
|
-
constructor(matchFn, callback) {
|
|
3
|
-
this.matchFn = matchFn;
|
|
4
|
-
this.callback = callback;
|
|
5
|
-
}
|
|
6
|
-
check(event) {
|
|
7
|
-
return this.matchFn(event);
|
|
8
|
-
}
|
|
9
|
-
async run(req, res) {
|
|
10
|
-
// Supply an empty callback as an equivalent of next() in Express.js.
|
|
11
|
-
await this.callback(req, res, () => { });
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import ERequest from "./request";
|
|
2
|
-
import EResponse from "./response";
|
|
3
|
-
export declare type RequestHandlerCallback = (req: ERequest, res: EResponse) => Promise<any>;
|
|
4
|
-
export declare class Route {
|
|
5
|
-
private matchFn;
|
|
6
|
-
private callback;
|
|
7
|
-
constructor(matchFn: Function, callback: RequestHandlerCallback);
|
|
8
|
-
check(event: ERequest): 0 | 404 | 405;
|
|
9
|
-
run(req: ERequest, res: EResponse): Promise<any>;
|
|
10
|
-
}
|