@webiny/handler 0.0.0-ee-vpcs.549378cf03
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/Context.d.ts +13 -0
- package/Context.js +29 -0
- package/Context.js.map +1 -0
- package/LICENSE +21 -0
- package/README.md +15 -0
- package/fastify.d.ts +8 -0
- package/fastify.js +407 -0
- package/fastify.js.map +1 -0
- package/index.d.ts +10 -0
- package/index.js +135 -0
- package/index.js.map +1 -0
- package/middleware.d.ts +4 -0
- package/middleware.js +51 -0
- package/middleware.js.map +1 -0
- package/package.json +47 -0
- package/plugins/BeforeHandlerPlugin.d.ts +12 -0
- package/plugins/BeforeHandlerPlugin.js +38 -0
- package/plugins/BeforeHandlerPlugin.js.map +1 -0
- package/plugins/EventPlugin.d.ts +25 -0
- package/plugins/EventPlugin.js +38 -0
- package/plugins/EventPlugin.js.map +1 -0
- package/plugins/HandlerErrorPlugin.d.ts +12 -0
- package/plugins/HandlerErrorPlugin.js +34 -0
- package/plugins/HandlerErrorPlugin.js.map +1 -0
- package/plugins/HandlerOnRequestPlugin.d.ts +20 -0
- package/plugins/HandlerOnRequestPlugin.js +34 -0
- package/plugins/HandlerOnRequestPlugin.js.map +1 -0
- package/plugins/HandlerResultPlugin.d.ts +12 -0
- package/plugins/HandlerResultPlugin.js +34 -0
- package/plugins/HandlerResultPlugin.js.map +1 -0
- package/plugins/ModifyFastifyPlugin.d.ts +13 -0
- package/plugins/ModifyFastifyPlugin.js +34 -0
- package/plugins/ModifyFastifyPlugin.js.map +1 -0
- package/plugins/RoutePlugin.d.ts +23 -0
- package/plugins/RoutePlugin.js +30 -0
- package/plugins/RoutePlugin.js.map +1 -0
- package/types.d.ts +45 -0
- package/types.js +19 -0
- package/types.js.map +1 -0
package/Context.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Context as BaseContext, ContextParams as BaseContextParams } from "@webiny/api";
|
|
2
|
+
import { Context as BaseContextType } from "./types";
|
|
3
|
+
export interface ContextParams extends BaseContextParams {
|
|
4
|
+
server: BaseContextType["server"];
|
|
5
|
+
routes: BaseContextType["routes"];
|
|
6
|
+
}
|
|
7
|
+
export declare class Context extends BaseContext implements BaseContextType {
|
|
8
|
+
readonly server: BaseContextType["server"];
|
|
9
|
+
readonly routes: BaseContextType["routes"];
|
|
10
|
+
handlerClient: BaseContextType["handlerClient"];
|
|
11
|
+
request: BaseContextType["request"];
|
|
12
|
+
constructor(params: ContextParams);
|
|
13
|
+
}
|
package/Context.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.Context = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _api = require("@webiny/api");
|
|
13
|
+
|
|
14
|
+
class Context extends _api.Context {
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
constructor(params) {
|
|
18
|
+
super(params);
|
|
19
|
+
(0, _defineProperty2.default)(this, "server", void 0);
|
|
20
|
+
(0, _defineProperty2.default)(this, "routes", void 0);
|
|
21
|
+
(0, _defineProperty2.default)(this, "handlerClient", void 0);
|
|
22
|
+
(0, _defineProperty2.default)(this, "request", void 0);
|
|
23
|
+
this.server = params.server;
|
|
24
|
+
this.routes = params.routes;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
exports.Context = Context;
|
package/Context.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Context","BaseContext","constructor","params","server","routes"],"sources":["Context.ts"],"sourcesContent":["import { Context as BaseContext, ContextParams as BaseContextParams } from \"@webiny/api\";\nimport { Context as BaseContextType } from \"~/types\";\n\nexport interface ContextParams extends BaseContextParams {\n server: BaseContextType[\"server\"];\n routes: BaseContextType[\"routes\"];\n}\n\nexport class Context extends BaseContext implements BaseContextType {\n public readonly server: BaseContextType[\"server\"];\n public readonly routes: BaseContextType[\"routes\"];\n // @ts-ignore\n public handlerClient: BaseContextType[\"handlerClient\"];\n // @ts-ignore\n public request: BaseContextType[\"request\"];\n\n public constructor(params: ContextParams) {\n super(params);\n this.server = params.server;\n this.routes = params.routes;\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAQO,MAAMA,OAAN,SAAsBC,YAAtB,CAA6D;EAGhE;EAEA;EAGOC,WAAW,CAACC,MAAD,EAAwB;IACtC,MAAMA,MAAN;IADsC;IAAA;IAAA;IAAA;IAEtC,KAAKC,MAAL,GAAcD,MAAM,CAACC,MAArB;IACA,KAAKC,MAAL,GAAcF,MAAM,CAACE,MAArB;EACH;;AAZ+D"}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Webiny
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @webiny/handler
|
|
2
|
+
[](https://www.npmjs.com/package/@webiny/handler)
|
|
3
|
+
[](https://www.npmjs.com/package/@webiny/handler)
|
|
4
|
+
[](https://github.com/prettier/prettier)
|
|
5
|
+
[](http://makeapullrequest.com)
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
```
|
|
9
|
+
npm install --save @webiny/handler
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Or if you prefer yarn:
|
|
13
|
+
```
|
|
14
|
+
yarn add @webiny/handler
|
|
15
|
+
```
|
package/fastify.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { PluginCollection } from "@webiny/plugins/types";
|
|
3
|
+
import { FastifyServerOptions as ServerOptions } from "fastify";
|
|
4
|
+
export interface CreateHandlerParams {
|
|
5
|
+
plugins: PluginCollection;
|
|
6
|
+
options?: ServerOptions;
|
|
7
|
+
}
|
|
8
|
+
export declare const createHandler: (params: CreateHandlerParams) => import("fastify").FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault> & PromiseLike<import("fastify").FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>>;
|
package/fastify.js
ADDED
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createHandler = void 0;
|
|
9
|
+
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
12
|
+
var _fastify = _interopRequireDefault(require("fastify"));
|
|
13
|
+
|
|
14
|
+
var _utils = require("@webiny/utils");
|
|
15
|
+
|
|
16
|
+
var _Context = require("./Context");
|
|
17
|
+
|
|
18
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
19
|
+
|
|
20
|
+
var _RoutePlugin = require("./plugins/RoutePlugin");
|
|
21
|
+
|
|
22
|
+
var _handlerClient = require("@webiny/handler-client");
|
|
23
|
+
|
|
24
|
+
var _cookie = _interopRequireDefault(require("@fastify/cookie"));
|
|
25
|
+
|
|
26
|
+
var _compress = _interopRequireDefault(require("@fastify/compress"));
|
|
27
|
+
|
|
28
|
+
var _middleware = require("./middleware");
|
|
29
|
+
|
|
30
|
+
var _api = require("@webiny/api");
|
|
31
|
+
|
|
32
|
+
var _BeforeHandlerPlugin = require("./plugins/BeforeHandlerPlugin");
|
|
33
|
+
|
|
34
|
+
var _HandlerResultPlugin = require("./plugins/HandlerResultPlugin");
|
|
35
|
+
|
|
36
|
+
var _HandlerErrorPlugin = require("./plugins/HandlerErrorPlugin");
|
|
37
|
+
|
|
38
|
+
var _ModifyFastifyPlugin = require("./plugins/ModifyFastifyPlugin");
|
|
39
|
+
|
|
40
|
+
var _HandlerOnRequestPlugin = require("./plugins/HandlerOnRequestPlugin");
|
|
41
|
+
|
|
42
|
+
const DEFAULT_HEADERS = (0, _objectSpread2.default)({
|
|
43
|
+
"Cache-Control": "no-store",
|
|
44
|
+
"Content-Type": "application/json; charset=utf-8",
|
|
45
|
+
"Access-Control-Allow-Origin": "*",
|
|
46
|
+
"Access-Control-Allow-Headers": "*",
|
|
47
|
+
"Access-Control-Allow-Methods": "OPTIONS,POST,GET,DELETE,PUT,PATCH"
|
|
48
|
+
}, (0, _utils.getWebinyVersionHeaders)());
|
|
49
|
+
|
|
50
|
+
const getDefaultHeaders = routes => {
|
|
51
|
+
/**
|
|
52
|
+
* If we are accepting all headers, just output that one.
|
|
53
|
+
*/
|
|
54
|
+
const keys = Object.keys(routes);
|
|
55
|
+
const all = keys.every(key => routes[key].length > 0);
|
|
56
|
+
|
|
57
|
+
if (all) {
|
|
58
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, DEFAULT_HEADERS), {}, {
|
|
59
|
+
"Access-Control-Allow-Methods": "*"
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, DEFAULT_HEADERS), {}, {
|
|
64
|
+
"Access-Control-Allow-Methods": keys.filter(key => {
|
|
65
|
+
const type = key;
|
|
66
|
+
|
|
67
|
+
if (!routes[type] || Array.isArray(routes[type]) === false) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return routes[type].length > 0;
|
|
72
|
+
}).sort().join(",")
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const OPTIONS_HEADERS = {
|
|
77
|
+
"Access-Control-Max-Age": "86400",
|
|
78
|
+
"Cache-Control": "public, max-age=86400"
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const createHandler = params => {
|
|
82
|
+
const definedRoutes = {
|
|
83
|
+
POST: [],
|
|
84
|
+
GET: [],
|
|
85
|
+
OPTIONS: [],
|
|
86
|
+
DELETE: [],
|
|
87
|
+
PATCH: [],
|
|
88
|
+
PUT: [],
|
|
89
|
+
HEAD: [],
|
|
90
|
+
COPY: [],
|
|
91
|
+
LOCK: [],
|
|
92
|
+
MKCOL: [],
|
|
93
|
+
MOVE: [],
|
|
94
|
+
PROPFIND: [],
|
|
95
|
+
PROPPATCH: [],
|
|
96
|
+
SEARCH: [],
|
|
97
|
+
TRACE: [],
|
|
98
|
+
UNLOCK: []
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const throwOnDefinedRoute = (type, path, options) => {
|
|
102
|
+
if (type === "ALL") {
|
|
103
|
+
const all = Object.keys(definedRoutes).some(key => {
|
|
104
|
+
const routes = definedRoutes[key];
|
|
105
|
+
return routes.includes(path);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
if (!all) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
throw new _error.default(`You cannot override a route with onAll() method, please remove unnecessary route from the system.`, "OVERRIDE_ROUTE_ERROR", {
|
|
113
|
+
type,
|
|
114
|
+
path
|
|
115
|
+
});
|
|
116
|
+
} else if (definedRoutes[type].includes(path) === false) {
|
|
117
|
+
return;
|
|
118
|
+
} else if ((options === null || options === void 0 ? void 0 : options.override) === true) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
throw new _error.default(`When you are trying to override existing route, you must send "override" parameter when adding that route.`, "OVERRIDE_ROUTE_ERROR", {
|
|
123
|
+
type,
|
|
124
|
+
path
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const addDefinedRoute = (inputType, path) => {
|
|
129
|
+
const type = inputType.toUpperCase();
|
|
130
|
+
|
|
131
|
+
if (!definedRoutes[type]) {
|
|
132
|
+
return;
|
|
133
|
+
} else if (definedRoutes[type].includes(path)) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
definedRoutes[type].push(path);
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* We must attach the server to our internal context if we want to have it accessible.
|
|
141
|
+
*/
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
const app = (0, _fastify.default)((0, _objectSpread2.default)({}, params.options || {}));
|
|
145
|
+
/**
|
|
146
|
+
* We need to register routes in our system so we can output headers later on and dissallow overriding routes.
|
|
147
|
+
*/
|
|
148
|
+
|
|
149
|
+
app.addHook("onRoute", route => {
|
|
150
|
+
const method = route.method;
|
|
151
|
+
|
|
152
|
+
if (Array.isArray(method)) {
|
|
153
|
+
for (const m of method) {
|
|
154
|
+
addDefinedRoute(m, route.path);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
addDefinedRoute(method, route.path);
|
|
161
|
+
});
|
|
162
|
+
/**
|
|
163
|
+
* ############################
|
|
164
|
+
* Register the Fastify plugins.
|
|
165
|
+
*/
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Package @fastify/cookie
|
|
169
|
+
*
|
|
170
|
+
* https://github.com/fastify/fastify-cookie
|
|
171
|
+
*/
|
|
172
|
+
|
|
173
|
+
app.register(_cookie.default, {
|
|
174
|
+
parseOptions: {} // options for parsing cookies
|
|
175
|
+
|
|
176
|
+
});
|
|
177
|
+
/**
|
|
178
|
+
* Package @fastify/compress
|
|
179
|
+
*
|
|
180
|
+
* https://github.com/fastify/fastify-compress
|
|
181
|
+
*/
|
|
182
|
+
|
|
183
|
+
app.register(_compress.default, {
|
|
184
|
+
global: true,
|
|
185
|
+
threshold: 1024,
|
|
186
|
+
onUnsupportedEncoding: (encoding, _, reply) => {
|
|
187
|
+
reply.code(406);
|
|
188
|
+
return `We do not support the ${encoding} encoding.`;
|
|
189
|
+
},
|
|
190
|
+
inflateIfDeflated: true
|
|
191
|
+
});
|
|
192
|
+
/**
|
|
193
|
+
* Route helpers - mostly for users.
|
|
194
|
+
*/
|
|
195
|
+
|
|
196
|
+
const routes = {
|
|
197
|
+
defined: definedRoutes,
|
|
198
|
+
onPost: (path, handler, options) => {
|
|
199
|
+
throwOnDefinedRoute("POST", path, options);
|
|
200
|
+
app.post(path, handler);
|
|
201
|
+
},
|
|
202
|
+
onGet: (path, handler, options) => {
|
|
203
|
+
throwOnDefinedRoute("GET", path, options);
|
|
204
|
+
app.get(path, handler);
|
|
205
|
+
},
|
|
206
|
+
onOptions: (path, handler, options) => {
|
|
207
|
+
throwOnDefinedRoute("OPTIONS", path, options);
|
|
208
|
+
app.options(path, handler);
|
|
209
|
+
},
|
|
210
|
+
onDelete: (path, handler, options) => {
|
|
211
|
+
throwOnDefinedRoute("DELETE", path, options);
|
|
212
|
+
app.delete(path, handler);
|
|
213
|
+
},
|
|
214
|
+
onPatch: (path, handler, options) => {
|
|
215
|
+
throwOnDefinedRoute("PATCH", path, options);
|
|
216
|
+
app.patch(path, handler);
|
|
217
|
+
},
|
|
218
|
+
onPut: (path, handler, options) => {
|
|
219
|
+
throwOnDefinedRoute("PUT", path, options);
|
|
220
|
+
app.put(path, handler);
|
|
221
|
+
},
|
|
222
|
+
onAll: (path, handler, options) => {
|
|
223
|
+
throwOnDefinedRoute("ALL", path, options);
|
|
224
|
+
app.all(path, handler);
|
|
225
|
+
},
|
|
226
|
+
onHead: (path, handler, options) => {
|
|
227
|
+
throwOnDefinedRoute("HEAD", path, options);
|
|
228
|
+
app.head(path, handler);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
const context = new _Context.Context({
|
|
232
|
+
plugins: [
|
|
233
|
+
/**
|
|
234
|
+
* We must have handlerClient by default.
|
|
235
|
+
* And it must be one of the first context plugins applied.
|
|
236
|
+
*/
|
|
237
|
+
(0, _handlerClient.createHandlerClient)(), ...(params.plugins || [])],
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Inserted via webpack on build time.
|
|
241
|
+
*/
|
|
242
|
+
WEBINY_VERSION: process.env.WEBINY_VERSION,
|
|
243
|
+
server: app,
|
|
244
|
+
routes
|
|
245
|
+
});
|
|
246
|
+
/**
|
|
247
|
+
* We are attaching our custom context to webiny variable on the fastify app so it is accessible everywhere
|
|
248
|
+
*/
|
|
249
|
+
|
|
250
|
+
app.decorate("webiny", context);
|
|
251
|
+
/**
|
|
252
|
+
* We have few types of triggers:
|
|
253
|
+
* * Events - EventPlugin
|
|
254
|
+
* * Routes - RoutePlugin
|
|
255
|
+
*
|
|
256
|
+
* Routes are registered in fastify but events must be handled in package which implements cloud specific methods.
|
|
257
|
+
*/
|
|
258
|
+
|
|
259
|
+
const routePlugins = app.webiny.plugins.byType(_RoutePlugin.RoutePlugin.type);
|
|
260
|
+
/**
|
|
261
|
+
* Add routes to the system.
|
|
262
|
+
*/
|
|
263
|
+
|
|
264
|
+
for (const plugin of routePlugins) {
|
|
265
|
+
plugin.cb((0, _objectSpread2.default)((0, _objectSpread2.default)({}, app.webiny.routes), {}, {
|
|
266
|
+
context: app.webiny
|
|
267
|
+
}));
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* On every request we add default headers, which can be changed later.
|
|
271
|
+
* Also, if it is an options request, we skip everything after this hook and output options headers.
|
|
272
|
+
*/
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
app.addHook("onRequest", async (request, reply) => {
|
|
276
|
+
/**
|
|
277
|
+
* Our default headers are always set. Users can override them.
|
|
278
|
+
*/
|
|
279
|
+
const defaultHeaders = getDefaultHeaders(definedRoutes);
|
|
280
|
+
reply.headers(defaultHeaders);
|
|
281
|
+
/**
|
|
282
|
+
* Users can define their own custom handlers for the onRequest event - so let's run them first.
|
|
283
|
+
*/
|
|
284
|
+
|
|
285
|
+
const plugins = app.webiny.plugins.byType(_HandlerOnRequestPlugin.HandlerOnRequestPlugin.type);
|
|
286
|
+
|
|
287
|
+
for (const plugin of plugins) {
|
|
288
|
+
const result = await plugin.exec(request, reply);
|
|
289
|
+
|
|
290
|
+
if (result === false) {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* When we receive the OPTIONS request, we end it before it goes any further as there is no need for anything to run after this - at least for our use cases.
|
|
296
|
+
*
|
|
297
|
+
* Users can prevent this by creating their own HandlerOnRequestPlugin and returning false as the result of the callable.
|
|
298
|
+
*/
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
if (request.method !== "OPTIONS") {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (reply.sent) {
|
|
306
|
+
/**
|
|
307
|
+
* At this point throwing an exception will not do anything with the response. So just log it.
|
|
308
|
+
*/
|
|
309
|
+
console.log(JSON.stringify({
|
|
310
|
+
message: `Output was already sent. Please check custom plugins of type "HandlerOnRequestPlugin".`,
|
|
311
|
+
explanation: "This error can happen if the user plugin ended the reply, but did not return false as response."
|
|
312
|
+
}));
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const raw = reply.code(204).hijack().raw;
|
|
317
|
+
const headers = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, defaultHeaders), OPTIONS_HEADERS);
|
|
318
|
+
|
|
319
|
+
for (const key in headers) {
|
|
320
|
+
raw.setHeader(key, headers[key]);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
raw.end("");
|
|
324
|
+
});
|
|
325
|
+
app.addHook("preParsing", async request => {
|
|
326
|
+
app.webiny.request = request;
|
|
327
|
+
const plugins = app.webiny.plugins.byType(_api.ContextPlugin.type);
|
|
328
|
+
|
|
329
|
+
for (const plugin of plugins) {
|
|
330
|
+
await plugin.apply(app.webiny);
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
/**
|
|
334
|
+
*
|
|
335
|
+
*/
|
|
336
|
+
|
|
337
|
+
app.addHook("preHandler", async () => {
|
|
338
|
+
const plugins = app.webiny.plugins.byType(_BeforeHandlerPlugin.BeforeHandlerPlugin.type);
|
|
339
|
+
|
|
340
|
+
for (const plugin of plugins) {
|
|
341
|
+
await plugin.apply(app.webiny);
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
/**
|
|
345
|
+
*
|
|
346
|
+
*/
|
|
347
|
+
|
|
348
|
+
const preSerialization = async (_, __, payload) => {
|
|
349
|
+
const plugins = app.webiny.plugins.byType(_HandlerResultPlugin.HandlerResultPlugin.type);
|
|
350
|
+
|
|
351
|
+
for (const plugin of plugins) {
|
|
352
|
+
await plugin.handle(app.webiny, payload);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return payload;
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
app.addHook("preSerialization", preSerialization);
|
|
359
|
+
app.setErrorHandler(async (error, request, reply) => {
|
|
360
|
+
return reply.status(500).headers({
|
|
361
|
+
"Cache-Control": "no-store"
|
|
362
|
+
}).send({
|
|
363
|
+
message: error.message,
|
|
364
|
+
code: error.code,
|
|
365
|
+
data: error.data
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
app.addHook("onError", async (_, reply, error) => {
|
|
369
|
+
const plugins = app.webiny.plugins.byType(_HandlerErrorPlugin.HandlerErrorPlugin.type);
|
|
370
|
+
/**
|
|
371
|
+
* Log error to cloud, as these can be extremely annoying to debug!
|
|
372
|
+
*/
|
|
373
|
+
|
|
374
|
+
console.log("@webiny/handler");
|
|
375
|
+
console.log(JSON.stringify((0, _objectSpread2.default)((0, _objectSpread2.default)({}, error), {}, {
|
|
376
|
+
message: error.message,
|
|
377
|
+
code: error.code,
|
|
378
|
+
data: error.data
|
|
379
|
+
})));
|
|
380
|
+
const handler = (0, _middleware.middleware)(plugins.map(pl => {
|
|
381
|
+
return (context, error, next) => {
|
|
382
|
+
return pl.handle(context, error, next);
|
|
383
|
+
};
|
|
384
|
+
}));
|
|
385
|
+
await handler(app.webiny, error);
|
|
386
|
+
return reply.send({
|
|
387
|
+
message: error.message,
|
|
388
|
+
code: error.code,
|
|
389
|
+
data: error.data
|
|
390
|
+
}).headers({
|
|
391
|
+
"Cache-Control": "no-store"
|
|
392
|
+
}).status(500);
|
|
393
|
+
});
|
|
394
|
+
/**
|
|
395
|
+
* With these plugins we give users possibility to do anything they want on our fastify instance.
|
|
396
|
+
*/
|
|
397
|
+
|
|
398
|
+
const modifyPlugins = app.webiny.plugins.byType(_ModifyFastifyPlugin.ModifyFastifyPlugin.type);
|
|
399
|
+
|
|
400
|
+
for (const plugin of modifyPlugins) {
|
|
401
|
+
plugin.modify(app);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
return app;
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
exports.createHandler = createHandler;
|
package/fastify.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["DEFAULT_HEADERS","getWebinyVersionHeaders","getDefaultHeaders","routes","keys","Object","all","every","key","length","filter","type","Array","isArray","sort","join","OPTIONS_HEADERS","createHandler","params","definedRoutes","POST","GET","OPTIONS","DELETE","PATCH","PUT","HEAD","COPY","LOCK","MKCOL","MOVE","PROPFIND","PROPPATCH","SEARCH","TRACE","UNLOCK","throwOnDefinedRoute","path","options","some","includes","WebinyError","override","addDefinedRoute","inputType","toUpperCase","push","app","fastify","addHook","route","method","m","register","fastifyCookie","parseOptions","fastifyCompress","global","threshold","onUnsupportedEncoding","encoding","_","reply","code","inflateIfDeflated","defined","onPost","handler","post","onGet","get","onOptions","onDelete","delete","onPatch","patch","onPut","put","onAll","onHead","head","context","Context","plugins","createHandlerClient","WEBINY_VERSION","process","env","server","decorate","routePlugins","webiny","byType","RoutePlugin","plugin","cb","request","defaultHeaders","headers","HandlerOnRequestPlugin","result","exec","sent","console","log","JSON","stringify","message","explanation","raw","hijack","setHeader","end","ContextPlugin","apply","BeforeHandlerPlugin","preSerialization","__","payload","HandlerResultPlugin","handle","setErrorHandler","error","status","send","data","HandlerErrorPlugin","middleware","map","pl","next","modifyPlugins","ModifyFastifyPlugin","modify"],"sources":["fastify.ts"],"sourcesContent":["import { PluginCollection } from \"@webiny/plugins/types\";\nimport fastify, {\n FastifyServerOptions as ServerOptions,\n preSerializationAsyncHookHandler\n} from \"fastify\";\nimport { getWebinyVersionHeaders } from \"@webiny/utils\";\nimport { ContextRoutes, DefinedContextRoutes, RouteMethodOptions, HTTPMethods } from \"~/types\";\nimport { Context } from \"~/Context\";\nimport WebinyError from \"@webiny/error\";\nimport { RoutePlugin } from \"./plugins/RoutePlugin\";\nimport { createHandlerClient } from \"@webiny/handler-client\";\nimport fastifyCookie from \"@fastify/cookie\";\nimport fastifyCompress from \"@fastify/compress\";\nimport { middleware } from \"~/middleware\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { BeforeHandlerPlugin } from \"./plugins/BeforeHandlerPlugin\";\nimport { HandlerResultPlugin } from \"./plugins/HandlerResultPlugin\";\nimport { HandlerErrorPlugin } from \"./plugins/HandlerErrorPlugin\";\nimport { ModifyFastifyPlugin } from \"~/plugins/ModifyFastifyPlugin\";\nimport { HandlerOnRequestPlugin } from \"~/plugins/HandlerOnRequestPlugin\";\n\nconst DEFAULT_HEADERS: Record<string, string> = {\n \"Cache-Control\": \"no-store\",\n \"Content-Type\": \"application/json; charset=utf-8\",\n \"Access-Control-Allow-Origin\": \"*\",\n \"Access-Control-Allow-Headers\": \"*\",\n \"Access-Control-Allow-Methods\": \"OPTIONS,POST,GET,DELETE,PUT,PATCH\",\n ...getWebinyVersionHeaders()\n};\n\nconst getDefaultHeaders = (routes: DefinedContextRoutes): Record<string, string> => {\n /**\n * If we are accepting all headers, just output that one.\n */\n const keys = Object.keys(routes);\n const all = keys.every(key => routes[key as HTTPMethods].length > 0);\n if (all) {\n return {\n ...DEFAULT_HEADERS,\n \"Access-Control-Allow-Methods\": \"*\"\n };\n }\n return {\n ...DEFAULT_HEADERS,\n \"Access-Control-Allow-Methods\": keys\n .filter(key => {\n const type = key as unknown as HTTPMethods;\n if (!routes[type] || Array.isArray(routes[type]) === false) {\n return false;\n }\n return routes[type].length > 0;\n })\n .sort()\n .join(\",\")\n };\n};\n\nconst OPTIONS_HEADERS: Record<string, string> = {\n \"Access-Control-Max-Age\": \"86400\",\n \"Cache-Control\": \"public, max-age=86400\"\n};\n\nexport interface CreateHandlerParams {\n plugins: PluginCollection;\n options?: ServerOptions;\n}\n\nexport const createHandler = (params: CreateHandlerParams) => {\n const definedRoutes: DefinedContextRoutes = {\n POST: [],\n GET: [],\n OPTIONS: [],\n DELETE: [],\n PATCH: [],\n PUT: [],\n HEAD: [],\n COPY: [],\n LOCK: [],\n MKCOL: [],\n MOVE: [],\n PROPFIND: [],\n PROPPATCH: [],\n SEARCH: [],\n TRACE: [],\n UNLOCK: []\n };\n\n const throwOnDefinedRoute = (\n type: HTTPMethods | \"ALL\",\n path: string,\n options?: RouteMethodOptions\n ): void => {\n if (type === \"ALL\") {\n const all = Object.keys(definedRoutes).some(key => {\n const routes = definedRoutes[key as HTTPMethods];\n return routes.includes(path);\n });\n if (!all) {\n return;\n }\n throw new WebinyError(\n `You cannot override a route with onAll() method, please remove unnecessary route from the system.`,\n \"OVERRIDE_ROUTE_ERROR\",\n {\n type,\n path\n }\n );\n } else if (definedRoutes[type].includes(path) === false) {\n return;\n } else if (options?.override === true) {\n return;\n }\n throw new WebinyError(\n `When you are trying to override existing route, you must send \"override\" parameter when adding that route.`,\n \"OVERRIDE_ROUTE_ERROR\",\n {\n type,\n path\n }\n );\n };\n\n const addDefinedRoute = (inputType: HTTPMethods, path: string): void => {\n const type = (inputType as string).toUpperCase() as HTTPMethods;\n if (!definedRoutes[type]) {\n return;\n } else if (definedRoutes[type].includes(path)) {\n return;\n }\n definedRoutes[type].push(path);\n };\n /**\n * We must attach the server to our internal context if we want to have it accessible.\n */\n const app = fastify({\n ...(params.options || {})\n });\n /**\n * We need to register routes in our system so we can output headers later on and dissallow overriding routes.\n */\n app.addHook(\"onRoute\", route => {\n const method = route.method;\n if (Array.isArray(method)) {\n for (const m of method) {\n addDefinedRoute(m, route.path);\n }\n return;\n }\n addDefinedRoute(method, route.path);\n });\n /**\n * ############################\n * Register the Fastify plugins.\n */\n /**\n * Package @fastify/cookie\n *\n * https://github.com/fastify/fastify-cookie\n */\n app.register(fastifyCookie, {\n parseOptions: {} // options for parsing cookies\n });\n /**\n * Package @fastify/compress\n *\n * https://github.com/fastify/fastify-compress\n */\n app.register(fastifyCompress, {\n global: true,\n threshold: 1024,\n onUnsupportedEncoding: (encoding, _, reply) => {\n reply.code(406);\n return `We do not support the ${encoding} encoding.`;\n },\n inflateIfDeflated: true\n });\n /**\n * Route helpers - mostly for users.\n */\n const routes: ContextRoutes = {\n defined: definedRoutes,\n onPost: (path, handler, options) => {\n throwOnDefinedRoute(\"POST\", path, options);\n app.post(path, handler);\n },\n onGet: (path, handler, options) => {\n throwOnDefinedRoute(\"GET\", path, options);\n app.get(path, handler);\n },\n onOptions: (path, handler, options) => {\n throwOnDefinedRoute(\"OPTIONS\", path, options);\n app.options(path, handler);\n },\n onDelete: (path, handler, options) => {\n throwOnDefinedRoute(\"DELETE\", path, options);\n app.delete(path, handler);\n },\n onPatch: (path, handler, options) => {\n throwOnDefinedRoute(\"PATCH\", path, options);\n app.patch(path, handler);\n },\n onPut: (path, handler, options) => {\n throwOnDefinedRoute(\"PUT\", path, options);\n app.put(path, handler);\n },\n onAll: (path, handler, options) => {\n throwOnDefinedRoute(\"ALL\", path, options);\n app.all(path, handler);\n },\n onHead: (path, handler, options) => {\n throwOnDefinedRoute(\"HEAD\", path, options);\n app.head(path, handler);\n }\n };\n const context = new Context({\n plugins: [\n /**\n * We must have handlerClient by default.\n * And it must be one of the first context plugins applied.\n */\n createHandlerClient(),\n ...(params.plugins || [])\n ],\n /**\n * Inserted via webpack on build time.\n */\n WEBINY_VERSION: process.env.WEBINY_VERSION as string,\n server: app,\n routes\n });\n /**\n * We are attaching our custom context to webiny variable on the fastify app so it is accessible everywhere\n */\n app.decorate(\"webiny\", context);\n\n /**\n * We have few types of triggers:\n * * Events - EventPlugin\n * * Routes - RoutePlugin\n *\n * Routes are registered in fastify but events must be handled in package which implements cloud specific methods.\n */\n const routePlugins = app.webiny.plugins.byType<RoutePlugin>(RoutePlugin.type);\n\n /**\n * Add routes to the system.\n */\n for (const plugin of routePlugins) {\n plugin.cb({\n ...app.webiny.routes,\n context: app.webiny\n });\n }\n\n /**\n * On every request we add default headers, which can be changed later.\n * Also, if it is an options request, we skip everything after this hook and output options headers.\n */\n app.addHook(\"onRequest\", async (request, reply) => {\n /**\n * Our default headers are always set. Users can override them.\n */\n const defaultHeaders = getDefaultHeaders(definedRoutes);\n reply.headers(defaultHeaders);\n /**\n * Users can define their own custom handlers for the onRequest event - so let's run them first.\n */\n const plugins = app.webiny.plugins.byType<HandlerOnRequestPlugin>(\n HandlerOnRequestPlugin.type\n );\n for (const plugin of plugins) {\n const result = await plugin.exec(request, reply);\n if (result === false) {\n return;\n }\n }\n /**\n * When we receive the OPTIONS request, we end it before it goes any further as there is no need for anything to run after this - at least for our use cases.\n *\n * Users can prevent this by creating their own HandlerOnRequestPlugin and returning false as the result of the callable.\n */\n if (request.method !== \"OPTIONS\") {\n return;\n }\n\n if (reply.sent) {\n /**\n * At this point throwing an exception will not do anything with the response. So just log it.\n */\n console.log(\n JSON.stringify({\n message: `Output was already sent. Please check custom plugins of type \"HandlerOnRequestPlugin\".`,\n explanation:\n \"This error can happen if the user plugin ended the reply, but did not return false as response.\"\n })\n );\n return;\n }\n const raw = reply.code(204).hijack().raw;\n const headers = { ...defaultHeaders, ...OPTIONS_HEADERS };\n for (const key in headers) {\n raw.setHeader(key, headers[key]);\n }\n\n raw.end(\"\");\n });\n\n app.addHook(\"preParsing\", async request => {\n app.webiny.request = request;\n const plugins = app.webiny.plugins.byType<ContextPlugin>(ContextPlugin.type);\n for (const plugin of plugins) {\n await plugin.apply(app.webiny);\n }\n });\n /**\n *\n */\n app.addHook(\"preHandler\", async () => {\n const plugins = app.webiny.plugins.byType<BeforeHandlerPlugin>(BeforeHandlerPlugin.type);\n for (const plugin of plugins) {\n await plugin.apply(app.webiny);\n }\n });\n\n /**\n *\n */\n const preSerialization: preSerializationAsyncHookHandler<any> = async (_, __, payload) => {\n const plugins = app.webiny.plugins.byType<HandlerResultPlugin>(HandlerResultPlugin.type);\n for (const plugin of plugins) {\n await plugin.handle(app.webiny, payload);\n }\n return payload;\n };\n\n app.addHook(\"preSerialization\", preSerialization);\n\n app.setErrorHandler<WebinyError>(async (error, request, reply) => {\n return reply\n .status(500)\n .headers({\n \"Cache-Control\": \"no-store\"\n })\n .send({\n message: error.message,\n code: error.code,\n data: error.data\n });\n });\n\n app.addHook(\"onError\", async (_, reply, error: any) => {\n const plugins = app.webiny.plugins.byType<HandlerErrorPlugin>(HandlerErrorPlugin.type);\n /**\n * Log error to cloud, as these can be extremely annoying to debug!\n */\n console.log(\"@webiny/handler\");\n console.log(\n JSON.stringify({\n ...error,\n message: error.message,\n code: error.code,\n data: error.data\n })\n );\n const handler = middleware(\n plugins.map(pl => {\n return (context: Context, error: Error, next: Function) => {\n return pl.handle(context, error, next);\n };\n })\n );\n await handler(app.webiny, error);\n\n return reply\n .send({\n message: error.message,\n code: error.code,\n data: error.data\n })\n .headers({\n \"Cache-Control\": \"no-store\"\n })\n .status(500);\n });\n\n /**\n * With these plugins we give users possibility to do anything they want on our fastify instance.\n */\n const modifyPlugins = app.webiny.plugins.byType<ModifyFastifyPlugin>(ModifyFastifyPlugin.type);\n for (const plugin of modifyPlugins) {\n plugin.modify(app);\n }\n\n return app;\n};\n"],"mappings":";;;;;;;;;;;AACA;;AAIA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA,MAAMA,eAAuC;EACzC,iBAAiB,UADwB;EAEzC,gBAAgB,iCAFyB;EAGzC,+BAA+B,GAHU;EAIzC,gCAAgC,GAJS;EAKzC,gCAAgC;AALS,GAMtC,IAAAC,8BAAA,GANsC,CAA7C;;AASA,MAAMC,iBAAiB,GAAIC,MAAD,IAA0D;EAChF;AACJ;AACA;EACI,MAAMC,IAAI,GAAGC,MAAM,CAACD,IAAP,CAAYD,MAAZ,CAAb;EACA,MAAMG,GAAG,GAAGF,IAAI,CAACG,KAAL,CAAWC,GAAG,IAAIL,MAAM,CAACK,GAAD,CAAN,CAA2BC,MAA3B,GAAoC,CAAtD,C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IAAI,EAAE2D,KAAK,CAAC3D,IAHhB;MAII8D,IAAI,EAAEH,KAAK,CAACG;IAJhB,GADJ;IAQA,MAAM1D,OAAO,GAAG,IAAA4D,sBAAA,EACZ5C,OAAO,CAAC6C,GAAR,CAAYC,EAAE,IAAI;MACd,OAAO,CAAChD,OAAD,EAAmByC,KAAnB,EAAiCQ,IAAjC,KAAoD;QACvD,OAAOD,EAAE,CAACT,MAAH,CAAUvC,OAAV,EAAmByC,KAAnB,EAA0BQ,IAA1B,CAAP;MACH,CAFD;IAGH,CAJD,CADY,CAAhB;IAOA,MAAM/D,OAAO,CAACpB,GAAG,CAAC4C,MAAL,EAAa+B,KAAb,CAAb;IAEA,OAAO5D,KAAK,CACP8D,IADE,CACG;MACFjB,OAAO,EAAEe,KAAK,CAACf,OADb;MAEF5C,IAAI,EAAE2D,KAAK,CAAC3D,IAFV;MAGF8D,IAAI,EAAEH,KAAK,CAACG;IAHV,CADH,EAMF3B,OANE,CAMM;MACL,iBAAiB;IADZ,CANN,EASFyB,MATE,CASK,GATL,CAAP;EAUH,CAjCD;EAmCA;AACJ;AACA;;EACI,MAAMQ,aAAa,GAAGpF,GAAG,CAAC4C,MAAJ,CAAWR,OAAX,CAAmBS,MAAnB,CAA+CwC,wCAAA,CAAoBzH,IAAnE,CAAtB;;EACA,KAAK,MAAMmF,MAAX,IAAqBqC,aAArB,EAAoC;IAChCrC,MAAM,CAACuC,MAAP,CAActF,GAAd;EACH;;EAED,OAAOA,GAAP;AACH,CAxUM"}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "@webiny/api/plugins/ContextPlugin";
|
|
2
|
+
export * from "./fastify";
|
|
3
|
+
export * from "./Context";
|
|
4
|
+
export * from "./plugins/EventPlugin";
|
|
5
|
+
export * from "./plugins/RoutePlugin";
|
|
6
|
+
export * from "./plugins/BeforeHandlerPlugin";
|
|
7
|
+
export * from "./plugins/HandlerErrorPlugin";
|
|
8
|
+
export * from "./plugins/HandlerResultPlugin";
|
|
9
|
+
export * from "./plugins/HandlerOnRequestPlugin";
|
|
10
|
+
export * from "./plugins/ModifyFastifyPlugin";
|