@webiny/handler 5.34.0 → 5.34.1-beta.0
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/fastify.js +12 -22
- package/fastify.js.map +1 -1
- package/package.json +9 -9
package/fastify.js
CHANGED
|
@@ -61,9 +61,7 @@ const getDefaultHeaders = routes => {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, DEFAULT_HEADERS), {}, {
|
|
64
|
-
"Access-Control-Allow-Methods": keys.filter(
|
|
65
|
-
const type = key;
|
|
66
|
-
|
|
64
|
+
"Access-Control-Allow-Methods": keys.filter(type => {
|
|
67
65
|
if (!routes[type] || Array.isArray(routes[type]) === false) {
|
|
68
66
|
return false;
|
|
69
67
|
}
|
|
@@ -125,9 +123,7 @@ const createHandler = params => {
|
|
|
125
123
|
});
|
|
126
124
|
};
|
|
127
125
|
|
|
128
|
-
const addDefinedRoute = (
|
|
129
|
-
const type = inputType.toUpperCase();
|
|
130
|
-
|
|
126
|
+
const addDefinedRoute = (type, path) => {
|
|
131
127
|
if (!definedRoutes[type]) {
|
|
132
128
|
return;
|
|
133
129
|
} else if (definedRoutes[type].includes(path)) {
|
|
@@ -244,7 +240,7 @@ const createHandler = params => {
|
|
|
244
240
|
routes
|
|
245
241
|
});
|
|
246
242
|
/**
|
|
247
|
-
* We are attaching our custom context to webiny variable on the fastify app so it is accessible everywhere
|
|
243
|
+
* We are attaching our custom context to webiny variable on the fastify app, so it is accessible everywhere.
|
|
248
244
|
*/
|
|
249
245
|
|
|
250
246
|
app.decorate("webiny", context);
|
|
@@ -313,14 +309,7 @@ const createHandler = params => {
|
|
|
313
309
|
return;
|
|
314
310
|
}
|
|
315
311
|
|
|
316
|
-
|
|
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("");
|
|
312
|
+
reply.headers((0, _objectSpread2.default)((0, _objectSpread2.default)({}, defaultHeaders), OPTIONS_HEADERS)).code(204).send("").hijack();
|
|
324
313
|
});
|
|
325
314
|
app.addHook("preParsing", async request => {
|
|
326
315
|
app.webiny.request = request;
|
|
@@ -377,19 +366,20 @@ const createHandler = params => {
|
|
|
377
366
|
code: error.code,
|
|
378
367
|
data: error.data
|
|
379
368
|
})));
|
|
369
|
+
reply.status(500).headers({
|
|
370
|
+
"Cache-Control": "no-store"
|
|
371
|
+
}).send({
|
|
372
|
+
message: error.message,
|
|
373
|
+
code: error.code,
|
|
374
|
+
data: error.data
|
|
375
|
+
});
|
|
380
376
|
const handler = (0, _middleware.middleware)(plugins.map(pl => {
|
|
381
377
|
return (context, error, next) => {
|
|
382
378
|
return pl.handle(context, error, next);
|
|
383
379
|
};
|
|
384
380
|
}));
|
|
385
381
|
await handler(app.webiny, error);
|
|
386
|
-
return reply
|
|
387
|
-
message: error.message,
|
|
388
|
-
code: error.code,
|
|
389
|
-
data: error.data
|
|
390
|
-
}).headers({
|
|
391
|
-
"Cache-Control": "no-store"
|
|
392
|
-
}).status(500);
|
|
382
|
+
return reply;
|
|
393
383
|
});
|
|
394
384
|
/**
|
|
395
385
|
* With these plugins we give users possibility to do anything they want on our fastify instance.
|
package/fastify.js.map
CHANGED
|
@@ -1 +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,CAAZ;;EACA,IAAIH,GAAJ,EAAS;IACL,mEACON,eADP;MAEI,gCAAgC;IAFpC;EAIH;;EACD,mEACOA,eADP;IAEI,gCAAgCI,IAAI,CAC/BM,MAD2B,CACpBF,GAAG,IAAI;MACX,MAAMG,IAAI,GAAGH,GAAb;;MACA,IAAI,CAACL,MAAM,CAACQ,IAAD,CAAP,IAAiBC,KAAK,CAACC,OAAN,CAAcV,MAAM,CAACQ,IAAD,CAApB,MAAgC,KAArD,EAA4D;QACxD,OAAO,KAAP;MACH;;MACD,OAAOR,MAAM,CAACQ,IAAD,CAAN,CAAaF,MAAb,GAAsB,CAA7B;IACH,CAP2B,EAQ3BK,IAR2B,GAS3BC,IAT2B,CAStB,GATsB;EAFpC;AAaH,CAzBD;;AA2BA,MAAMC,eAAuC,GAAG;EAC5C,0BAA0B,OADkB;EAE5C,iBAAiB;AAF2B,CAAhD;;AAUO,MAAMC,a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K,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"}
|
|
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","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","send","hijack","ContextPlugin","apply","BeforeHandlerPlugin","preSerialization","__","payload","HandlerResultPlugin","handle","setErrorHandler","error","status","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) as HTTPMethods[];\n const all = keys.every(key => routes[key].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(type => {\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 = (type: HTTPMethods, path: string): void => {\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\n reply\n .headers({ ...defaultHeaders, ...OPTIONS_HEADERS })\n .code(204)\n .send(\"\")\n .hijack();\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\n 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 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 });\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,CAAYC,MAAZ,GAAqB,CAA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EF,KAAK,CAACE;IAHV,CALV;IAWA,MAAMvD,OAAO,GAAG,IAAAyD,sBAAA,EACZzC,OAAO,CAAC0C,GAAR,CAAYC,EAAE,IAAI;MACd,OAAO,CAAC7C,OAAD,EAAmBuC,KAAnB,EAAiCO,IAAjC,KAAoD;QACvD,OAAOD,EAAE,CAACR,MAAH,CAAUrC,OAAV,EAAmBuC,KAAnB,EAA0BO,IAA1B,CAAP;MACH,CAFD;IAGH,CAJD,CADY,CAAhB;IAOA,MAAM5D,OAAO,CAACpB,GAAG,CAAC4C,MAAL,EAAa6B,KAAb,CAAb;IAEA,OAAO1D,KAAP;EACH,CApCD;EAsCA;AACJ;AACA;;EACI,MAAMkE,aAAa,GAAGjF,GAAG,CAAC4C,MAAJ,CAAWR,OAAX,CAAmBS,MAAnB,CAA+CqC,wCAAA,CAAoBpH,IAAnE,CAAtB;;EACA,KAAK,MAAMiF,MAAX,IAAqBkC,aAArB,EAAoC;IAChClC,MAAM,CAACoC,MAAP,CAAcnF,GAAd;EACH;;EAED,OAAOA,GAAP;AACH,CAzUM"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/handler",
|
|
3
|
-
"version": "5.34.0",
|
|
3
|
+
"version": "5.34.1-beta.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -15,11 +15,11 @@
|
|
|
15
15
|
"@babel/runtime": "7.19.0",
|
|
16
16
|
"@fastify/compress": "6.2.0",
|
|
17
17
|
"@fastify/cookie": "8.3.0",
|
|
18
|
-
"@webiny/api": "5.34.0",
|
|
19
|
-
"@webiny/error": "5.34.0",
|
|
20
|
-
"@webiny/handler-client": "5.34.0",
|
|
21
|
-
"@webiny/plugins": "5.34.0",
|
|
22
|
-
"@webiny/utils": "5.34.0",
|
|
18
|
+
"@webiny/api": "5.34.1-beta.0",
|
|
19
|
+
"@webiny/error": "5.34.1-beta.0",
|
|
20
|
+
"@webiny/handler-client": "5.34.1-beta.0",
|
|
21
|
+
"@webiny/plugins": "5.34.1-beta.0",
|
|
22
|
+
"@webiny/utils": "5.34.1-beta.0",
|
|
23
23
|
"fastify": "4.11.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"@babel/core": "^7.19.3",
|
|
28
28
|
"@babel/preset-env": "^7.19.4",
|
|
29
29
|
"@babel/preset-typescript": "^7.18.6",
|
|
30
|
-
"@webiny/cli": "^5.34.0",
|
|
31
|
-
"@webiny/project-utils": "^5.34.0",
|
|
30
|
+
"@webiny/cli": "^5.34.1-beta.0",
|
|
31
|
+
"@webiny/project-utils": "^5.34.1-beta.0",
|
|
32
32
|
"babel-plugin-lodash": "^3.3.4",
|
|
33
33
|
"merge": "^1.2.1",
|
|
34
34
|
"rimraf": "^3.0.2",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"build": "yarn webiny run build",
|
|
44
44
|
"watch": "yarn webiny run watch"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "c893b6c771e45d4b2ea13da4f17455abdaef8239"
|
|
47
47
|
}
|