@webiny/handler 5.42.0 → 5.42.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/PreHandler/IPreHandler.d.ts +8 -0
- package/PreHandler/IPreHandler.js +13 -0
- package/PreHandler/IPreHandler.js.map +1 -0
- package/PreHandler/IfNotOptionsRequest.d.ts +7 -0
- package/PreHandler/IfNotOptionsRequest.js +28 -0
- package/PreHandler/IfNotOptionsRequest.js.map +1 -0
- package/PreHandler/IfOptionsRequest.d.ts +7 -0
- package/PreHandler/IfOptionsRequest.js +28 -0
- package/PreHandler/IfOptionsRequest.js.map +1 -0
- package/PreHandler/PreHandler.d.ts +7 -0
- package/PreHandler/PreHandler.js +24 -0
- package/PreHandler/PreHandler.js.map +1 -0
- package/PreHandler/ProcessBeforeHandlerPlugins.d.ts +9 -0
- package/PreHandler/ProcessBeforeHandlerPlugins.js +31 -0
- package/PreHandler/ProcessBeforeHandlerPlugins.js.map +1 -0
- package/PreHandler/ProcessContextPlugins.d.ts +9 -0
- package/PreHandler/ProcessContextPlugins.js +31 -0
- package/PreHandler/ProcessContextPlugins.js.map +1 -0
- package/PreHandler/ProcessHandlerOnRequestPlugins.d.ts +8 -0
- package/PreHandler/ProcessHandlerOnRequestPlugins.js +33 -0
- package/PreHandler/ProcessHandlerOnRequestPlugins.js.map +1 -0
- package/PreHandler/SendEarlyOptionsResponse.d.ts +8 -0
- package/PreHandler/SendEarlyOptionsResponse.js +35 -0
- package/PreHandler/SendEarlyOptionsResponse.js.map +1 -0
- package/PreHandler/SetDefaultHeaders.d.ts +8 -0
- package/PreHandler/SetDefaultHeaders.js +64 -0
- package/PreHandler/SetDefaultHeaders.js.map +1 -0
- package/fastify.js +46 -145
- package/fastify.js.map +1 -1
- package/package.json +9 -9
- package/stringifyError.d.ts +5 -0
- package/stringifyError.js +27 -0
- package/stringifyError.js.map +1 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Action = void 0;
|
|
7
|
+
let Action = exports.Action = /*#__PURE__*/function (Action) {
|
|
8
|
+
Action["CONTINUE"] = "continue";
|
|
9
|
+
Action["DONE"] = "done";
|
|
10
|
+
return Action;
|
|
11
|
+
}({});
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=IPreHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Action","exports"],"sources":["IPreHandler.ts"],"sourcesContent":["import type { FastifyReply, FastifyRequest } from \"fastify\";\n\nexport enum Action {\n CONTINUE = \"continue\",\n DONE = \"done\"\n}\n\nexport interface IPreHandler {\n execute(request: FastifyRequest, reply: FastifyReply): Promise<Action> | Action;\n}\n"],"mappings":";;;;;;IAEYA,MAAM,GAAAC,OAAA,CAAAD,MAAA,0BAANA,MAAM;EAANA,MAAM;EAANA,MAAM;EAAA,OAANA,MAAM;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
2
|
+
import { Action, IPreHandler } from "./IPreHandler";
|
|
3
|
+
export declare class IfNotOptionsRequest implements IPreHandler {
|
|
4
|
+
private readonly handlers;
|
|
5
|
+
constructor(handlers: IPreHandler[]);
|
|
6
|
+
execute(request: FastifyRequest, reply: FastifyReply): Promise<Action>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.IfNotOptionsRequest = void 0;
|
|
7
|
+
var _IPreHandler = require("./IPreHandler");
|
|
8
|
+
class IfNotOptionsRequest {
|
|
9
|
+
constructor(handlers) {
|
|
10
|
+
this.handlers = handlers;
|
|
11
|
+
}
|
|
12
|
+
async execute(request, reply) {
|
|
13
|
+
const isOptionsRequest = request.method === "OPTIONS";
|
|
14
|
+
if (isOptionsRequest) {
|
|
15
|
+
return _IPreHandler.Action.CONTINUE;
|
|
16
|
+
}
|
|
17
|
+
for (const handler of this.handlers) {
|
|
18
|
+
const action = await handler.execute(request, reply);
|
|
19
|
+
if (action === _IPreHandler.Action.DONE) {
|
|
20
|
+
return _IPreHandler.Action.DONE;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return _IPreHandler.Action.CONTINUE;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.IfNotOptionsRequest = IfNotOptionsRequest;
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=IfNotOptionsRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_IPreHandler","require","IfNotOptionsRequest","constructor","handlers","execute","request","reply","isOptionsRequest","method","Action","CONTINUE","handler","action","DONE","exports"],"sources":["IfNotOptionsRequest.ts"],"sourcesContent":["import type { FastifyReply, FastifyRequest } from \"fastify\";\nimport { Action, IPreHandler } from \"./IPreHandler\";\n\nexport class IfNotOptionsRequest implements IPreHandler {\n private readonly handlers: IPreHandler[];\n\n constructor(handlers: IPreHandler[]) {\n this.handlers = handlers;\n }\n\n async execute(request: FastifyRequest, reply: FastifyReply): Promise<Action> {\n const isOptionsRequest = request.method === \"OPTIONS\";\n if (isOptionsRequest) {\n return Action.CONTINUE;\n }\n\n for (const handler of this.handlers) {\n const action = await handler.execute(request, reply);\n if (action === Action.DONE) {\n return Action.DONE;\n }\n }\n\n return Action.CONTINUE;\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAEO,MAAMC,mBAAmB,CAAwB;EAGpDC,WAAWA,CAACC,QAAuB,EAAE;IACjC,IAAI,CAACA,QAAQ,GAAGA,QAAQ;EAC5B;EAEA,MAAMC,OAAOA,CAACC,OAAuB,EAAEC,KAAmB,EAAmB;IACzE,MAAMC,gBAAgB,GAAGF,OAAO,CAACG,MAAM,KAAK,SAAS;IACrD,IAAID,gBAAgB,EAAE;MAClB,OAAOE,mBAAM,CAACC,QAAQ;IAC1B;IAEA,KAAK,MAAMC,OAAO,IAAI,IAAI,CAACR,QAAQ,EAAE;MACjC,MAAMS,MAAM,GAAG,MAAMD,OAAO,CAACP,OAAO,CAACC,OAAO,EAAEC,KAAK,CAAC;MACpD,IAAIM,MAAM,KAAKH,mBAAM,CAACI,IAAI,EAAE;QACxB,OAAOJ,mBAAM,CAACI,IAAI;MACtB;IACJ;IAEA,OAAOJ,mBAAM,CAACC,QAAQ;EAC1B;AACJ;AAACI,OAAA,CAAAb,mBAAA,GAAAA,mBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
2
|
+
import { Action, IPreHandler } from "./IPreHandler";
|
|
3
|
+
export declare class IfOptionsRequest implements IPreHandler {
|
|
4
|
+
private readonly handlers;
|
|
5
|
+
constructor(handlers: IPreHandler[]);
|
|
6
|
+
execute(request: FastifyRequest, reply: FastifyReply): Promise<Action>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.IfOptionsRequest = void 0;
|
|
7
|
+
var _IPreHandler = require("./IPreHandler");
|
|
8
|
+
class IfOptionsRequest {
|
|
9
|
+
constructor(handlers) {
|
|
10
|
+
this.handlers = handlers;
|
|
11
|
+
}
|
|
12
|
+
async execute(request, reply) {
|
|
13
|
+
const isOptionsRequest = request.method === "OPTIONS";
|
|
14
|
+
if (!isOptionsRequest) {
|
|
15
|
+
return _IPreHandler.Action.CONTINUE;
|
|
16
|
+
}
|
|
17
|
+
for (const handler of this.handlers) {
|
|
18
|
+
const action = await handler.execute(request, reply);
|
|
19
|
+
if (action === _IPreHandler.Action.DONE) {
|
|
20
|
+
return _IPreHandler.Action.DONE;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return _IPreHandler.Action.CONTINUE;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.IfOptionsRequest = IfOptionsRequest;
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=IfOptionsRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_IPreHandler","require","IfOptionsRequest","constructor","handlers","execute","request","reply","isOptionsRequest","method","Action","CONTINUE","handler","action","DONE","exports"],"sources":["IfOptionsRequest.ts"],"sourcesContent":["import type { FastifyReply, FastifyRequest } from \"fastify\";\nimport { Action, IPreHandler } from \"./IPreHandler\";\n\nexport class IfOptionsRequest implements IPreHandler {\n private readonly handlers: IPreHandler[];\n\n constructor(handlers: IPreHandler[]) {\n this.handlers = handlers;\n }\n\n async execute(request: FastifyRequest, reply: FastifyReply): Promise<Action> {\n const isOptionsRequest = request.method === \"OPTIONS\";\n if (!isOptionsRequest) {\n return Action.CONTINUE;\n }\n\n for (const handler of this.handlers) {\n const action = await handler.execute(request, reply);\n if (action === Action.DONE) {\n return Action.DONE;\n }\n }\n\n return Action.CONTINUE;\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAEO,MAAMC,gBAAgB,CAAwB;EAGjDC,WAAWA,CAACC,QAAuB,EAAE;IACjC,IAAI,CAACA,QAAQ,GAAGA,QAAQ;EAC5B;EAEA,MAAMC,OAAOA,CAACC,OAAuB,EAAEC,KAAmB,EAAmB;IACzE,MAAMC,gBAAgB,GAAGF,OAAO,CAACG,MAAM,KAAK,SAAS;IACrD,IAAI,CAACD,gBAAgB,EAAE;MACnB,OAAOE,mBAAM,CAACC,QAAQ;IAC1B;IAEA,KAAK,MAAMC,OAAO,IAAI,IAAI,CAACR,QAAQ,EAAE;MACjC,MAAMS,MAAM,GAAG,MAAMD,OAAO,CAACP,OAAO,CAACC,OAAO,EAAEC,KAAK,CAAC;MACpD,IAAIM,MAAM,KAAKH,mBAAM,CAACI,IAAI,EAAE;QACxB,OAAOJ,mBAAM,CAACI,IAAI;MACtB;IACJ;IAEA,OAAOJ,mBAAM,CAACC,QAAQ;EAC1B;AACJ;AAACI,OAAA,CAAAb,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FastifyReply, FastifyRequest } from "fastify";
|
|
2
|
+
import { Action, IPreHandler } from "./IPreHandler";
|
|
3
|
+
export declare class PreHandler implements IPreHandler {
|
|
4
|
+
private readonly handlers;
|
|
5
|
+
constructor(handlers: IPreHandler[]);
|
|
6
|
+
execute(request: FastifyRequest, reply: FastifyReply): Promise<Action>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.PreHandler = void 0;
|
|
7
|
+
var _IPreHandler = require("./IPreHandler");
|
|
8
|
+
class PreHandler {
|
|
9
|
+
constructor(handlers) {
|
|
10
|
+
this.handlers = handlers;
|
|
11
|
+
}
|
|
12
|
+
async execute(request, reply) {
|
|
13
|
+
for (const handler of this.handlers) {
|
|
14
|
+
const action = await handler.execute(request, reply);
|
|
15
|
+
if (action === _IPreHandler.Action.DONE) {
|
|
16
|
+
return _IPreHandler.Action.DONE;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return _IPreHandler.Action.CONTINUE;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.PreHandler = PreHandler;
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=PreHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_IPreHandler","require","PreHandler","constructor","handlers","execute","request","reply","handler","action","Action","DONE","CONTINUE","exports"],"sources":["PreHandler.ts"],"sourcesContent":["import { FastifyReply, FastifyRequest } from \"fastify\";\nimport { Action, IPreHandler } from \"~/PreHandler/IPreHandler\";\n\nexport class PreHandler implements IPreHandler {\n private readonly handlers: IPreHandler[];\n\n constructor(handlers: IPreHandler[]) {\n this.handlers = handlers;\n }\n\n async execute(request: FastifyRequest, reply: FastifyReply): Promise<Action> {\n for (const handler of this.handlers) {\n const action = await handler.execute(request, reply);\n if (action === Action.DONE) {\n return Action.DONE;\n }\n }\n\n return Action.CONTINUE;\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAEO,MAAMC,UAAU,CAAwB;EAG3CC,WAAWA,CAACC,QAAuB,EAAE;IACjC,IAAI,CAACA,QAAQ,GAAGA,QAAQ;EAC5B;EAEA,MAAMC,OAAOA,CAACC,OAAuB,EAAEC,KAAmB,EAAmB;IACzE,KAAK,MAAMC,OAAO,IAAI,IAAI,CAACJ,QAAQ,EAAE;MACjC,MAAMK,MAAM,GAAG,MAAMD,OAAO,CAACH,OAAO,CAACC,OAAO,EAAEC,KAAK,CAAC;MACpD,IAAIE,MAAM,KAAKC,mBAAM,CAACC,IAAI,EAAE;QACxB,OAAOD,mBAAM,CAACC,IAAI;MACtB;IACJ;IAEA,OAAOD,mBAAM,CAACE,QAAQ;EAC1B;AACJ;AAACC,OAAA,CAAAX,UAAA,GAAAA,UAAA","ignoreList":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Action, IPreHandler } from "./IPreHandler";
|
|
2
|
+
import type { Context } from "../types";
|
|
3
|
+
import { BeforeHandlerPlugin } from "../plugins/BeforeHandlerPlugin";
|
|
4
|
+
export declare class ProcessBeforeHandlerPlugins implements IPreHandler {
|
|
5
|
+
private readonly plugins;
|
|
6
|
+
private readonly context;
|
|
7
|
+
constructor(context: Context, plugins: BeforeHandlerPlugin[]);
|
|
8
|
+
execute(): Promise<Action>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ProcessBeforeHandlerPlugins = void 0;
|
|
7
|
+
var _IPreHandler = require("./IPreHandler");
|
|
8
|
+
var _stringifyError = require("../stringifyError");
|
|
9
|
+
class ProcessBeforeHandlerPlugins {
|
|
10
|
+
constructor(context, plugins) {
|
|
11
|
+
this.context = context;
|
|
12
|
+
this.plugins = plugins;
|
|
13
|
+
}
|
|
14
|
+
async execute() {
|
|
15
|
+
let name;
|
|
16
|
+
try {
|
|
17
|
+
for (const plugin of this.plugins) {
|
|
18
|
+
name = plugin.name;
|
|
19
|
+
await plugin.apply(this.context);
|
|
20
|
+
}
|
|
21
|
+
} catch (ex) {
|
|
22
|
+
console.error(`Error running BeforeHandlerPlugin "${name}".`);
|
|
23
|
+
console.error((0, _stringifyError.stringifyError)(ex));
|
|
24
|
+
throw ex;
|
|
25
|
+
}
|
|
26
|
+
return _IPreHandler.Action.CONTINUE;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.ProcessBeforeHandlerPlugins = ProcessBeforeHandlerPlugins;
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=ProcessBeforeHandlerPlugins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_IPreHandler","require","_stringifyError","ProcessBeforeHandlerPlugins","constructor","context","plugins","execute","name","plugin","apply","ex","console","error","stringifyError","Action","CONTINUE","exports"],"sources":["ProcessBeforeHandlerPlugins.ts"],"sourcesContent":["import { Action, IPreHandler } from \"~/PreHandler/IPreHandler\";\nimport { stringifyError } from \"~/stringifyError\";\nimport type { Context } from \"~/types\";\nimport { BeforeHandlerPlugin } from \"~/plugins/BeforeHandlerPlugin\";\n\nexport class ProcessBeforeHandlerPlugins implements IPreHandler {\n private readonly plugins: BeforeHandlerPlugin[];\n private readonly context: Context;\n\n constructor(context: Context, plugins: BeforeHandlerPlugin[]) {\n this.context = context;\n this.plugins = plugins;\n }\n\n async execute(): Promise<Action> {\n let name: string | undefined;\n try {\n for (const plugin of this.plugins) {\n name = plugin.name;\n await plugin.apply(this.context);\n }\n } catch (ex) {\n console.error(`Error running BeforeHandlerPlugin \"${name}\".`);\n console.error(stringifyError(ex));\n throw ex;\n }\n\n return Action.CONTINUE;\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AAIO,MAAME,2BAA2B,CAAwB;EAI5DC,WAAWA,CAACC,OAAgB,EAAEC,OAA8B,EAAE;IAC1D,IAAI,CAACD,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACC,OAAO,GAAGA,OAAO;EAC1B;EAEA,MAAMC,OAAOA,CAAA,EAAoB;IAC7B,IAAIC,IAAwB;IAC5B,IAAI;MACA,KAAK,MAAMC,MAAM,IAAI,IAAI,CAACH,OAAO,EAAE;QAC/BE,IAAI,GAAGC,MAAM,CAACD,IAAI;QAClB,MAAMC,MAAM,CAACC,KAAK,CAAC,IAAI,CAACL,OAAO,CAAC;MACpC;IACJ,CAAC,CAAC,OAAOM,EAAE,EAAE;MACTC,OAAO,CAACC,KAAK,CAAC,sCAAsCL,IAAI,IAAI,CAAC;MAC7DI,OAAO,CAACC,KAAK,CAAC,IAAAC,8BAAc,EAACH,EAAE,CAAC,CAAC;MACjC,MAAMA,EAAE;IACZ;IAEA,OAAOI,mBAAM,CAACC,QAAQ;EAC1B;AACJ;AAACC,OAAA,CAAAd,2BAAA,GAAAA,2BAAA","ignoreList":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Action, IPreHandler } from "./IPreHandler";
|
|
2
|
+
import { ContextPlugin } from "../Context";
|
|
3
|
+
import type { Context } from "../types";
|
|
4
|
+
export declare class ProcessContextPlugins implements IPreHandler {
|
|
5
|
+
private readonly plugins;
|
|
6
|
+
private readonly context;
|
|
7
|
+
constructor(context: Context, plugins: ContextPlugin[]);
|
|
8
|
+
execute(): Promise<Action>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ProcessContextPlugins = void 0;
|
|
7
|
+
var _IPreHandler = require("./IPreHandler");
|
|
8
|
+
var _stringifyError = require("../stringifyError");
|
|
9
|
+
class ProcessContextPlugins {
|
|
10
|
+
constructor(context, plugins) {
|
|
11
|
+
this.context = context;
|
|
12
|
+
this.plugins = plugins;
|
|
13
|
+
}
|
|
14
|
+
async execute() {
|
|
15
|
+
let name;
|
|
16
|
+
try {
|
|
17
|
+
for (const plugin of this.plugins) {
|
|
18
|
+
name = plugin.name;
|
|
19
|
+
await plugin.apply(this.context);
|
|
20
|
+
}
|
|
21
|
+
} catch (ex) {
|
|
22
|
+
console.error(`Error running ContextPlugin "${name}".`);
|
|
23
|
+
console.error((0, _stringifyError.stringifyError)(ex));
|
|
24
|
+
throw ex;
|
|
25
|
+
}
|
|
26
|
+
return _IPreHandler.Action.CONTINUE;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.ProcessContextPlugins = ProcessContextPlugins;
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=ProcessContextPlugins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_IPreHandler","require","_stringifyError","ProcessContextPlugins","constructor","context","plugins","execute","name","plugin","apply","ex","console","error","stringifyError","Action","CONTINUE","exports"],"sources":["ProcessContextPlugins.ts"],"sourcesContent":["import { Action, IPreHandler } from \"~/PreHandler/IPreHandler\";\nimport { stringifyError } from \"~/stringifyError\";\nimport { ContextPlugin } from \"~/Context\";\nimport type { Context } from \"~/types\";\n\nexport class ProcessContextPlugins implements IPreHandler {\n private readonly plugins: ContextPlugin[];\n private readonly context: Context;\n\n constructor(context: Context, plugins: ContextPlugin[]) {\n this.context = context;\n this.plugins = plugins;\n }\n\n async execute(): Promise<Action> {\n let name: string | undefined;\n try {\n for (const plugin of this.plugins) {\n name = plugin.name;\n await plugin.apply(this.context);\n }\n } catch (ex) {\n console.error(`Error running ContextPlugin \"${name}\".`);\n console.error(stringifyError(ex));\n throw ex;\n }\n\n return Action.CONTINUE;\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AAIO,MAAME,qBAAqB,CAAwB;EAItDC,WAAWA,CAACC,OAAgB,EAAEC,OAAwB,EAAE;IACpD,IAAI,CAACD,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACC,OAAO,GAAGA,OAAO;EAC1B;EAEA,MAAMC,OAAOA,CAAA,EAAoB;IAC7B,IAAIC,IAAwB;IAC5B,IAAI;MACA,KAAK,MAAMC,MAAM,IAAI,IAAI,CAACH,OAAO,EAAE;QAC/BE,IAAI,GAAGC,MAAM,CAACD,IAAI;QAClB,MAAMC,MAAM,CAACC,KAAK,CAAC,IAAI,CAACL,OAAO,CAAC;MACpC;IACJ,CAAC,CAAC,OAAOM,EAAE,EAAE;MACTC,OAAO,CAACC,KAAK,CAAC,gCAAgCL,IAAI,IAAI,CAAC;MACvDI,OAAO,CAACC,KAAK,CAAC,IAAAC,8BAAc,EAACH,EAAE,CAAC,CAAC;MACjC,MAAMA,EAAE;IACZ;IAEA,OAAOI,mBAAM,CAACC,QAAQ;EAC1B;AACJ;AAACC,OAAA,CAAAd,qBAAA,GAAAA,qBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
2
|
+
import { Action, IPreHandler } from "./IPreHandler";
|
|
3
|
+
import { HandlerOnRequestPlugin } from "../plugins/HandlerOnRequestPlugin";
|
|
4
|
+
export declare class ProcessHandlerOnRequestPlugins implements IPreHandler {
|
|
5
|
+
private readonly plugins;
|
|
6
|
+
constructor(plugins: HandlerOnRequestPlugin[]);
|
|
7
|
+
execute(request: FastifyRequest, reply: FastifyReply): Promise<Action>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ProcessHandlerOnRequestPlugins = void 0;
|
|
7
|
+
var _IPreHandler = require("./IPreHandler");
|
|
8
|
+
var _stringifyError = require("../stringifyError");
|
|
9
|
+
class ProcessHandlerOnRequestPlugins {
|
|
10
|
+
constructor(plugins) {
|
|
11
|
+
this.plugins = plugins;
|
|
12
|
+
}
|
|
13
|
+
async execute(request, reply) {
|
|
14
|
+
let name;
|
|
15
|
+
try {
|
|
16
|
+
for (const plugin of this.plugins) {
|
|
17
|
+
name = plugin.name;
|
|
18
|
+
const result = await plugin.exec(request, reply);
|
|
19
|
+
if (result === false) {
|
|
20
|
+
return _IPreHandler.Action.DONE;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
} catch (ex) {
|
|
24
|
+
console.error(`Error while running the "HandlerOnRequestPlugin" ${name ? `(${name})` : ""} plugin in the onRequest hook.`);
|
|
25
|
+
console.error((0, _stringifyError.stringifyError)(ex));
|
|
26
|
+
throw ex;
|
|
27
|
+
}
|
|
28
|
+
return _IPreHandler.Action.CONTINUE;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.ProcessHandlerOnRequestPlugins = ProcessHandlerOnRequestPlugins;
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=ProcessHandlerOnRequestPlugins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_IPreHandler","require","_stringifyError","ProcessHandlerOnRequestPlugins","constructor","plugins","execute","request","reply","name","plugin","result","exec","Action","DONE","ex","console","error","stringifyError","CONTINUE","exports"],"sources":["ProcessHandlerOnRequestPlugins.ts"],"sourcesContent":["import type { FastifyReply, FastifyRequest } from \"fastify\";\nimport { Action, IPreHandler } from \"~/PreHandler/IPreHandler\";\nimport { HandlerOnRequestPlugin } from \"~/plugins/HandlerOnRequestPlugin\";\nimport { stringifyError } from \"~/stringifyError\";\n\nexport class ProcessHandlerOnRequestPlugins implements IPreHandler {\n private readonly plugins: HandlerOnRequestPlugin[];\n\n constructor(plugins: HandlerOnRequestPlugin[]) {\n this.plugins = plugins;\n }\n\n async execute(request: FastifyRequest, reply: FastifyReply): Promise<Action> {\n let name: string | undefined;\n try {\n for (const plugin of this.plugins) {\n name = plugin.name;\n const result = await plugin.exec(request, reply);\n if (result === false) {\n return Action.DONE;\n }\n }\n } catch (ex) {\n console.error(\n `Error while running the \"HandlerOnRequestPlugin\" ${\n name ? `(${name})` : \"\"\n } plugin in the onRequest hook.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\n\n return Action.CONTINUE;\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,eAAA,GAAAD,OAAA;AAEO,MAAME,8BAA8B,CAAwB;EAG/DC,WAAWA,CAACC,OAAiC,EAAE;IAC3C,IAAI,CAACA,OAAO,GAAGA,OAAO;EAC1B;EAEA,MAAMC,OAAOA,CAACC,OAAuB,EAAEC,KAAmB,EAAmB;IACzE,IAAIC,IAAwB;IAC5B,IAAI;MACA,KAAK,MAAMC,MAAM,IAAI,IAAI,CAACL,OAAO,EAAE;QAC/BI,IAAI,GAAGC,MAAM,CAACD,IAAI;QAClB,MAAME,MAAM,GAAG,MAAMD,MAAM,CAACE,IAAI,CAACL,OAAO,EAAEC,KAAK,CAAC;QAChD,IAAIG,MAAM,KAAK,KAAK,EAAE;UAClB,OAAOE,mBAAM,CAACC,IAAI;QACtB;MACJ;IACJ,CAAC,CAAC,OAAOC,EAAE,EAAE;MACTC,OAAO,CAACC,KAAK,CACT,oDACIR,IAAI,GAAG,IAAIA,IAAI,GAAG,GAAG,EAAE,gCAE/B,CAAC;MACDO,OAAO,CAACC,KAAK,CAAC,IAAAC,8BAAc,EAACH,EAAE,CAAC,CAAC;MACjC,MAAMA,EAAE;IACZ;IAEA,OAAOF,mBAAM,CAACM,QAAQ;EAC1B;AACJ;AAACC,OAAA,CAAAjB,8BAAA,GAAAA,8BAAA","ignoreList":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FastifyReply, FastifyRequest } from "fastify";
|
|
2
|
+
import { Action, IPreHandler } from "./IPreHandler";
|
|
3
|
+
import { ModifyResponseHeadersPlugin } from "../plugins/ModifyResponseHeadersPlugin";
|
|
4
|
+
export declare class SendEarlyOptionsResponse implements IPreHandler {
|
|
5
|
+
private readonly plugins;
|
|
6
|
+
constructor(plugins: ModifyResponseHeadersPlugin[]);
|
|
7
|
+
execute(request: FastifyRequest, reply: FastifyReply): Promise<Action>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SendEarlyOptionsResponse = void 0;
|
|
7
|
+
var _IPreHandler = require("./IPreHandler");
|
|
8
|
+
var _ResponseHeaders = require("../ResponseHeaders");
|
|
9
|
+
class SendEarlyOptionsResponse {
|
|
10
|
+
constructor(plugins) {
|
|
11
|
+
this.plugins = plugins;
|
|
12
|
+
}
|
|
13
|
+
async execute(request, reply) {
|
|
14
|
+
if (reply.sent) {
|
|
15
|
+
/**
|
|
16
|
+
* At this point throwing an exception will not do anything with the response. So just log it.
|
|
17
|
+
*/
|
|
18
|
+
console.error(JSON.stringify({
|
|
19
|
+
message: `Output was already sent. Please check custom plugins of type "HandlerOnRequestPlugin".`,
|
|
20
|
+
explanation: "This error can happen if the user plugin ended the reply, but did not return false as response."
|
|
21
|
+
}));
|
|
22
|
+
return _IPreHandler.Action.DONE;
|
|
23
|
+
}
|
|
24
|
+
const headers = _ResponseHeaders.ResponseHeaders.create(reply.getHeaders());
|
|
25
|
+
this.plugins.forEach(plugin => {
|
|
26
|
+
plugin.modify(request, headers);
|
|
27
|
+
});
|
|
28
|
+
reply.headers(headers.getHeaders());
|
|
29
|
+
reply.code(204).send("").hijack();
|
|
30
|
+
return _IPreHandler.Action.DONE;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.SendEarlyOptionsResponse = SendEarlyOptionsResponse;
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=SendEarlyOptionsResponse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_IPreHandler","require","_ResponseHeaders","SendEarlyOptionsResponse","constructor","plugins","execute","request","reply","sent","console","error","JSON","stringify","message","explanation","Action","DONE","headers","ResponseHeaders","create","getHeaders","forEach","plugin","modify","code","send","hijack","exports"],"sources":["SendEarlyOptionsResponse.ts"],"sourcesContent":["import { FastifyReply, FastifyRequest } from \"fastify\";\nimport { Action, IPreHandler } from \"~/PreHandler/IPreHandler\";\nimport { ModifyResponseHeadersPlugin } from \"~/plugins/ModifyResponseHeadersPlugin\";\nimport { ResponseHeaders } from \"~/ResponseHeaders\";\n\nexport class SendEarlyOptionsResponse implements IPreHandler {\n private readonly plugins: ModifyResponseHeadersPlugin[];\n\n constructor(plugins: ModifyResponseHeadersPlugin[]) {\n this.plugins = plugins;\n }\n\n async execute(request: FastifyRequest, reply: FastifyReply): Promise<Action> {\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.error(\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 Action.DONE;\n }\n\n const headers = ResponseHeaders.create(reply.getHeaders());\n\n this.plugins.forEach(plugin => {\n plugin.modify(request, headers);\n });\n\n reply.headers(headers.getHeaders());\n\n reply.code(204).send(\"\").hijack();\n\n return Action.DONE;\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,gBAAA,GAAAD,OAAA;AAEO,MAAME,wBAAwB,CAAwB;EAGzDC,WAAWA,CAACC,OAAsC,EAAE;IAChD,IAAI,CAACA,OAAO,GAAGA,OAAO;EAC1B;EAEA,MAAMC,OAAOA,CAACC,OAAuB,EAAEC,KAAmB,EAAmB;IACzE,IAAIA,KAAK,CAACC,IAAI,EAAE;MACZ;AACZ;AACA;MACYC,OAAO,CAACC,KAAK,CACTC,IAAI,CAACC,SAAS,CAAC;QACXC,OAAO,EAAE,wFAAwF;QACjGC,WAAW,EACP;MACR,CAAC,CACL,CAAC;MACD,OAAOC,mBAAM,CAACC,IAAI;IACtB;IAEA,MAAMC,OAAO,GAAGC,gCAAe,CAACC,MAAM,CAACZ,KAAK,CAACa,UAAU,CAAC,CAAC,CAAC;IAE1D,IAAI,CAAChB,OAAO,CAACiB,OAAO,CAACC,MAAM,IAAI;MAC3BA,MAAM,CAACC,MAAM,CAACjB,OAAO,EAAEW,OAAO,CAAC;IACnC,CAAC,CAAC;IAEFV,KAAK,CAACU,OAAO,CAACA,OAAO,CAACG,UAAU,CAAC,CAAC,CAAC;IAEnCb,KAAK,CAACiB,IAAI,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC,EAAE,CAAC,CAACC,MAAM,CAAC,CAAC;IAEjC,OAAOX,mBAAM,CAACC,IAAI;EACtB;AACJ;AAACW,OAAA,CAAAzB,wBAAA,GAAAA,wBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
2
|
+
import { DefinedContextRoutes } from "../types";
|
|
3
|
+
import { Action, IPreHandler } from "./IPreHandler";
|
|
4
|
+
export declare class SetDefaultHeaders implements IPreHandler {
|
|
5
|
+
private readonly definedRoutes;
|
|
6
|
+
constructor(definedRoutes: DefinedContextRoutes);
|
|
7
|
+
execute(request: FastifyRequest, reply: FastifyReply): Action;
|
|
8
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SetDefaultHeaders = void 0;
|
|
7
|
+
var _utils = require("@webiny/utils");
|
|
8
|
+
var _ResponseHeaders = require("../ResponseHeaders");
|
|
9
|
+
var _IPreHandler = require("./IPreHandler");
|
|
10
|
+
function createDefaultHeaders() {
|
|
11
|
+
return _ResponseHeaders.ResponseHeaders.create({
|
|
12
|
+
"content-type": "application/json; charset=utf-8",
|
|
13
|
+
"cache-control": "no-store",
|
|
14
|
+
"access-control-allow-origin": "*",
|
|
15
|
+
"access-control-allow-headers": "*",
|
|
16
|
+
"access-control-allow-methods": "OPTIONS,POST,GET,DELETE,PUT,PATCH",
|
|
17
|
+
...(0, _utils.getWebinyVersionHeaders)()
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
const getDefaultOptionsHeaders = () => {
|
|
21
|
+
return _ResponseHeaders.ResponseHeaders.create({
|
|
22
|
+
"access-control-max-age": "86400",
|
|
23
|
+
"cache-control": "public, max-age=86400"
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
const getDefaultHeaders = routes => {
|
|
27
|
+
const headers = createDefaultHeaders();
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* If we are accepting all headers, just output that one.
|
|
31
|
+
*/
|
|
32
|
+
const keys = Object.keys(routes);
|
|
33
|
+
const all = keys.every(key => routes[key].length > 0);
|
|
34
|
+
if (all) {
|
|
35
|
+
headers.set("access-control-allow-methods", "*");
|
|
36
|
+
} else {
|
|
37
|
+
const allowedMethods = keys.filter(type => {
|
|
38
|
+
if (!routes[type] || !Array.isArray(routes[type])) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return routes[type].length > 0;
|
|
42
|
+
}).sort().join(",");
|
|
43
|
+
headers.set("access-control-allow-methods", allowedMethods);
|
|
44
|
+
}
|
|
45
|
+
return headers;
|
|
46
|
+
};
|
|
47
|
+
class SetDefaultHeaders {
|
|
48
|
+
constructor(definedRoutes) {
|
|
49
|
+
this.definedRoutes = definedRoutes;
|
|
50
|
+
}
|
|
51
|
+
execute(request, reply) {
|
|
52
|
+
const isOptionsRequest = request.method === "OPTIONS";
|
|
53
|
+
/**
|
|
54
|
+
* Our default headers are always set. Users can override them.
|
|
55
|
+
*/
|
|
56
|
+
const defaultHeaders = getDefaultHeaders(this.definedRoutes);
|
|
57
|
+
const initialHeaders = isOptionsRequest ? defaultHeaders.merge(getDefaultOptionsHeaders()) : defaultHeaders;
|
|
58
|
+
reply.headers(initialHeaders.getHeaders());
|
|
59
|
+
return _IPreHandler.Action.CONTINUE;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.SetDefaultHeaders = SetDefaultHeaders;
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=SetDefaultHeaders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_utils","require","_ResponseHeaders","_IPreHandler","createDefaultHeaders","ResponseHeaders","create","getWebinyVersionHeaders","getDefaultOptionsHeaders","getDefaultHeaders","routes","headers","keys","Object","all","every","key","length","set","allowedMethods","filter","type","Array","isArray","sort","join","SetDefaultHeaders","constructor","definedRoutes","execute","request","reply","isOptionsRequest","method","defaultHeaders","initialHeaders","merge","getHeaders","Action","CONTINUE","exports"],"sources":["SetDefaultHeaders.ts"],"sourcesContent":["import type { FastifyReply, FastifyRequest } from \"fastify\";\nimport { getWebinyVersionHeaders } from \"@webiny/utils\";\nimport { ResponseHeaders } from \"~/ResponseHeaders\";\nimport { DefinedContextRoutes, HTTPMethods } from \"~/types\";\nimport { Action, IPreHandler } from \"~/PreHandler/IPreHandler\";\n\nfunction createDefaultHeaders() {\n return ResponseHeaders.create({\n \"content-type\": \"application/json; charset=utf-8\",\n \"cache-control\": \"no-store\",\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}\n\nconst getDefaultOptionsHeaders = () => {\n return ResponseHeaders.create({\n \"access-control-max-age\": \"86400\",\n \"cache-control\": \"public, max-age=86400\"\n });\n};\n\nconst getDefaultHeaders = (routes: DefinedContextRoutes): ResponseHeaders => {\n const headers = createDefaultHeaders();\n\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 headers.set(\"access-control-allow-methods\", \"*\");\n } else {\n const allowedMethods = keys\n .filter(type => {\n if (!routes[type] || !Array.isArray(routes[type])) {\n return false;\n }\n return routes[type].length > 0;\n })\n .sort()\n .join(\",\");\n\n headers.set(\"access-control-allow-methods\", allowedMethods);\n }\n\n return headers;\n};\n\nexport class SetDefaultHeaders implements IPreHandler {\n private readonly definedRoutes: DefinedContextRoutes;\n\n constructor(definedRoutes: DefinedContextRoutes) {\n this.definedRoutes = definedRoutes;\n }\n\n execute(request: FastifyRequest, reply: FastifyReply) {\n const isOptionsRequest = request.method === \"OPTIONS\";\n /**\n * Our default headers are always set. Users can override them.\n */\n const defaultHeaders = getDefaultHeaders(this.definedRoutes);\n\n const initialHeaders = isOptionsRequest\n ? defaultHeaders.merge(getDefaultOptionsHeaders())\n : defaultHeaders;\n\n reply.headers(initialHeaders.getHeaders());\n\n return Action.CONTINUE;\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AAEA,IAAAE,YAAA,GAAAF,OAAA;AAEA,SAASG,oBAAoBA,CAAA,EAAG;EAC5B,OAAOC,gCAAe,CAACC,MAAM,CAAC;IAC1B,cAAc,EAAE,iCAAiC;IACjD,eAAe,EAAE,UAAU;IAC3B,6BAA6B,EAAE,GAAG;IAClC,8BAA8B,EAAE,GAAG;IACnC,8BAA8B,E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F,OAAO,CAACG,MAAM,KAAK,SAAS;IACrD;AACR;AACA;IACQ,MAAMC,cAAc,GAAGzB,iBAAiB,CAAC,IAAI,CAACmB,aAAa,CAAC;IAE5D,MAAMO,cAAc,GAAGH,gBAAgB,GACjCE,cAAc,CAACE,KAAK,CAAC5B,wBAAwB,CAAC,CAAC,CAAC,GAChD0B,cAAc;IAEpBH,KAAK,CAACpB,OAAO,CAACwB,cAAc,CAACE,UAAU,CAAC,CAAC,CAAC;IAE1C,OAAOC,mBAAM,CAACC,QAAQ;EAC1B;AACJ;AAACC,OAAA,CAAAd,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
package/fastify.js
CHANGED
|
@@ -22,61 +22,15 @@ var _ModifyFastifyPlugin = require("./plugins/ModifyFastifyPlugin");
|
|
|
22
22
|
var _HandlerOnRequestPlugin = require("./plugins/HandlerOnRequestPlugin");
|
|
23
23
|
var _ResponseHeaders = require("./ResponseHeaders");
|
|
24
24
|
var _ModifyResponseHeadersPlugin = require("./plugins/ModifyResponseHeadersPlugin");
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
const getDefaultOptionsHeaders = () => {
|
|
36
|
-
return _ResponseHeaders.ResponseHeaders.create({
|
|
37
|
-
"access-control-max-age": "86400",
|
|
38
|
-
"cache-control": "public, max-age=86400"
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
const getDefaultHeaders = routes => {
|
|
42
|
-
const headers = createDefaultHeaders();
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* If we are accepting all headers, just output that one.
|
|
46
|
-
*/
|
|
47
|
-
const keys = Object.keys(routes);
|
|
48
|
-
const all = keys.every(key => routes[key].length > 0);
|
|
49
|
-
if (all) {
|
|
50
|
-
headers.set("access-control-allow-methods", "*");
|
|
51
|
-
} else {
|
|
52
|
-
const allowedMethods = keys.filter(type => {
|
|
53
|
-
if (!routes[type] || !Array.isArray(routes[type])) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
return routes[type].length > 0;
|
|
57
|
-
}).sort().join(",");
|
|
58
|
-
headers.set("access-control-allow-methods", allowedMethods);
|
|
59
|
-
}
|
|
60
|
-
return headers;
|
|
61
|
-
};
|
|
62
|
-
const stringifyError = error => {
|
|
63
|
-
const {
|
|
64
|
-
name,
|
|
65
|
-
message,
|
|
66
|
-
code,
|
|
67
|
-
stack,
|
|
68
|
-
data
|
|
69
|
-
} = error;
|
|
70
|
-
return JSON.stringify({
|
|
71
|
-
...error,
|
|
72
|
-
constructorName: error.constructor?.name || "UnknownError",
|
|
73
|
-
name: name || "No error name",
|
|
74
|
-
message: message || "No error message",
|
|
75
|
-
code: code || "NO_CODE",
|
|
76
|
-
data,
|
|
77
|
-
stack: process.env.DEBUG === "true" ? stack : "Turn on the debug flag to see the stack."
|
|
78
|
-
});
|
|
79
|
-
};
|
|
25
|
+
var _SetDefaultHeaders = require("./PreHandler/SetDefaultHeaders");
|
|
26
|
+
var _PreHandler = require("./PreHandler/PreHandler");
|
|
27
|
+
var _stringifyError = require("./stringifyError");
|
|
28
|
+
var _ProcessHandlerOnRequestPlugins = require("./PreHandler/ProcessHandlerOnRequestPlugins");
|
|
29
|
+
var _ProcessContextPlugins = require("./PreHandler/ProcessContextPlugins");
|
|
30
|
+
var _IfNotOptionsRequest = require("./PreHandler/IfNotOptionsRequest");
|
|
31
|
+
var _ProcessBeforeHandlerPlugins = require("./PreHandler/ProcessBeforeHandlerPlugins");
|
|
32
|
+
var _IfOptionsRequest = require("./PreHandler/IfOptionsRequest");
|
|
33
|
+
var _SendEarlyOptionsResponse = require("./PreHandler/SendEarlyOptionsResponse");
|
|
80
34
|
const modifyResponseHeaders = (app, request, reply) => {
|
|
81
35
|
const modifyHeaders = app.webiny.plugins.byType(_ModifyResponseHeadersPlugin.ModifyResponseHeadersPlugin.type);
|
|
82
36
|
const headers = _ResponseHeaders.ResponseHeaders.create(reply.getHeaders());
|
|
@@ -150,7 +104,7 @@ const createHandler = params => {
|
|
|
150
104
|
});
|
|
151
105
|
|
|
152
106
|
/**
|
|
153
|
-
* We need to register routes in our system
|
|
107
|
+
* We need to register routes in our system to output headers later on, and disallow route overriding.
|
|
154
108
|
*/
|
|
155
109
|
app.addHook("onRoute", route => {
|
|
156
110
|
const method = route.method;
|
|
@@ -245,7 +199,7 @@ const createHandler = params => {
|
|
|
245
199
|
});
|
|
246
200
|
} catch (ex) {
|
|
247
201
|
console.error(`Error while constructing the Context.`);
|
|
248
|
-
console.error(stringifyError(ex));
|
|
202
|
+
console.error((0, _stringifyError.stringifyError)(ex));
|
|
249
203
|
throw ex;
|
|
250
204
|
}
|
|
251
205
|
|
|
@@ -255,94 +209,36 @@ const createHandler = params => {
|
|
|
255
209
|
app.decorate("webiny", context);
|
|
256
210
|
|
|
257
211
|
/**
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
*/
|
|
261
|
-
app.addHook("onRequest", async (request, reply) => {
|
|
262
|
-
const isOptionsRequest = request.method === "OPTIONS";
|
|
263
|
-
/**
|
|
264
|
-
* Our default headers are always set. Users can override them.
|
|
265
|
-
*/
|
|
266
|
-
const defaultHeaders = getDefaultHeaders(definedRoutes);
|
|
267
|
-
const initialHeaders = isOptionsRequest ? defaultHeaders.merge(getDefaultOptionsHeaders()) : defaultHeaders;
|
|
268
|
-
reply.headers(initialHeaders.getHeaders());
|
|
269
|
-
/**
|
|
270
|
-
* Users can define their own custom handlers for the onRequest event - so let's run them first.
|
|
271
|
-
*/
|
|
272
|
-
const plugins = app.webiny.plugins.byType(_HandlerOnRequestPlugin.HandlerOnRequestPlugin.type);
|
|
273
|
-
let name;
|
|
274
|
-
try {
|
|
275
|
-
for (const plugin of plugins) {
|
|
276
|
-
name = plugin.name;
|
|
277
|
-
const result = await plugin.exec(request, reply);
|
|
278
|
-
if (result === false) {
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
} catch (ex) {
|
|
283
|
-
console.error(`Error while running the "HandlerOnRequestPlugin" ${name ? `(${name})` : ""} plugin in the onRequest hook.`);
|
|
284
|
-
console.error(stringifyError(ex));
|
|
285
|
-
throw ex;
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* 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.
|
|
289
|
-
*
|
|
290
|
-
* Users can prevent this by creating their own HandlerOnRequestPlugin and returning false as the result of the callable.
|
|
291
|
-
*/
|
|
292
|
-
if (!isOptionsRequest) {
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
if (reply.sent) {
|
|
296
|
-
/**
|
|
297
|
-
* At this point throwing an exception will not do anything with the response. So just log it.
|
|
298
|
-
*/
|
|
299
|
-
console.error(JSON.stringify({
|
|
300
|
-
message: `Output was already sent. Please check custom plugins of type "HandlerOnRequestPlugin".`,
|
|
301
|
-
explanation: "This error can happen if the user plugin ended the reply, but did not return false as response."
|
|
302
|
-
}));
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
modifyResponseHeaders(app, request, reply);
|
|
306
|
-
reply.code(204).send("").hijack();
|
|
307
|
-
});
|
|
308
|
-
app.addHook("preParsing", async (request, reply) => {
|
|
309
|
-
app.webiny.request = request;
|
|
310
|
-
app.webiny.reply = reply;
|
|
311
|
-
const plugins = app.webiny.plugins.byType(_api.ContextPlugin.type);
|
|
312
|
-
let name;
|
|
313
|
-
try {
|
|
314
|
-
for (const plugin of plugins) {
|
|
315
|
-
name = plugin.name;
|
|
316
|
-
await plugin.apply(app.webiny);
|
|
317
|
-
}
|
|
318
|
-
} catch (ex) {
|
|
319
|
-
console.error(`Error while running the "ContextPlugin" ${name ? `(${name})` : ""} plugin in the preParsing hook.`);
|
|
320
|
-
console.error(stringifyError(ex));
|
|
321
|
-
throw ex;
|
|
322
|
-
}
|
|
323
|
-
});
|
|
324
|
-
/**
|
|
212
|
+
* With this we ensure that an undefined request body is not parsed on OPTIONS requests,
|
|
213
|
+
* in case there's a `content-type` header set for whatever reason.
|
|
325
214
|
*
|
|
215
|
+
* @see https://fastify.dev/docs/latest/Reference/ContentTypeParser/#content-type-parser
|
|
326
216
|
*/
|
|
327
|
-
app.addHook("
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
try {
|
|
331
|
-
for (const plugin of plugins) {
|
|
332
|
-
name = plugin.name;
|
|
333
|
-
await plugin.apply(app.webiny);
|
|
334
|
-
}
|
|
335
|
-
} catch (ex) {
|
|
336
|
-
console.error(`Error while running the "BeforeHandlerPlugin" ${name ? `(${name})` : ""} plugin in the preHandler hook.`);
|
|
337
|
-
console.error(stringifyError(ex));
|
|
338
|
-
throw ex;
|
|
217
|
+
app.addHook("onRequest", async request => {
|
|
218
|
+
if (request.method === "OPTIONS" && request.body === undefined) {
|
|
219
|
+
request.headers["content-type"] = undefined;
|
|
339
220
|
}
|
|
340
221
|
});
|
|
341
222
|
|
|
342
223
|
/**
|
|
343
|
-
*
|
|
224
|
+
* At this point, request body is properly parsed, and we can execute Webiny business logic.
|
|
225
|
+
* - set default headers
|
|
226
|
+
* - process `HandlerOnRequestPlugin`
|
|
227
|
+
* - if OPTIONS request, exit early
|
|
228
|
+
* - process `ContextPlugin`
|
|
229
|
+
* - process `BeforeHandlerPlugin`
|
|
344
230
|
*/
|
|
345
|
-
|
|
231
|
+
app.addHook("preHandler", async (request, reply) => {
|
|
232
|
+
app.webiny.request = request;
|
|
233
|
+
app.webiny.reply = reply;
|
|
234
|
+
const handlerOnRequestPlugins = app.webiny.plugins.byType(_HandlerOnRequestPlugin.HandlerOnRequestPlugin.type);
|
|
235
|
+
const contextPlugins = app.webiny.plugins.byType(_api.ContextPlugin.type);
|
|
236
|
+
const beforeHandlerPlugins = app.webiny.plugins.byType(_BeforeHandlerPlugin.BeforeHandlerPlugin.type);
|
|
237
|
+
const modifyHeadersPlugins = app.webiny.plugins.byType(_ModifyResponseHeadersPlugin.ModifyResponseHeadersPlugin.type);
|
|
238
|
+
const preHandler = new _PreHandler.PreHandler([new _SetDefaultHeaders.SetDefaultHeaders(definedRoutes), new _ProcessHandlerOnRequestPlugins.ProcessHandlerOnRequestPlugins(handlerOnRequestPlugins), new _IfNotOptionsRequest.IfNotOptionsRequest([new _ProcessContextPlugins.ProcessContextPlugins(app.webiny, contextPlugins), new _ProcessBeforeHandlerPlugins.ProcessBeforeHandlerPlugins(app.webiny, beforeHandlerPlugins)]), new _IfOptionsRequest.IfOptionsRequest([new _SendEarlyOptionsResponse.SendEarlyOptionsResponse(modifyHeadersPlugins)])]);
|
|
239
|
+
await preHandler.execute(request, reply);
|
|
240
|
+
});
|
|
241
|
+
app.addHook("preSerialization", async (_, __, payload) => {
|
|
346
242
|
const plugins = app.webiny.plugins.byType(_HandlerResultPlugin.HandlerResultPlugin.type);
|
|
347
243
|
let name;
|
|
348
244
|
try {
|
|
@@ -352,12 +248,11 @@ const createHandler = params => {
|
|
|
352
248
|
}
|
|
353
249
|
} catch (ex) {
|
|
354
250
|
console.error(`Error while running the "HandlerResultPlugin" ${name ? `(${name})` : ""} plugin in the preSerialization hook.`);
|
|
355
|
-
console.error(stringifyError(ex));
|
|
251
|
+
console.error((0, _stringifyError.stringifyError)(ex));
|
|
356
252
|
throw ex;
|
|
357
253
|
}
|
|
358
254
|
return payload;
|
|
359
|
-
};
|
|
360
|
-
app.addHook("preSerialization", preSerialization);
|
|
255
|
+
});
|
|
361
256
|
app.setErrorHandler(async (error, request, reply) => {
|
|
362
257
|
return reply.status(500).headers({
|
|
363
258
|
"Cache-Control": "no-store"
|
|
@@ -371,13 +266,19 @@ const createHandler = params => {
|
|
|
371
266
|
data: error.data
|
|
372
267
|
}));
|
|
373
268
|
});
|
|
374
|
-
app.addHook("onError", async (
|
|
269
|
+
app.addHook("onError", async (request, reply, error) => {
|
|
375
270
|
const plugins = app.webiny.plugins.byType(_HandlerErrorPlugin.HandlerErrorPlugin.type);
|
|
376
271
|
/**
|
|
377
272
|
* Log error to cloud, as these can be extremely annoying to debug!
|
|
378
273
|
*/
|
|
379
274
|
console.error("@webiny/handler");
|
|
380
|
-
console.
|
|
275
|
+
console.log({
|
|
276
|
+
url: request.url,
|
|
277
|
+
method: request.method,
|
|
278
|
+
headers: request.headers,
|
|
279
|
+
body: request.body
|
|
280
|
+
});
|
|
281
|
+
console.error((0, _stringifyError.stringifyError)(error));
|
|
381
282
|
reply.status(500).headers({
|
|
382
283
|
"Cache-Control": "no-store"
|
|
383
284
|
}).send(
|
|
@@ -428,7 +329,7 @@ const createHandler = params => {
|
|
|
428
329
|
}
|
|
429
330
|
} catch (ex) {
|
|
430
331
|
console.error(`Error while running the "ModifyFastifyPlugin" ${modifyFastifyPluginName ? `(${modifyFastifyPluginName})` : ""} plugin in the end of the "createHandler" callable.`);
|
|
431
|
-
console.error(stringifyError(ex));
|
|
332
|
+
console.error((0, _stringifyError.stringifyError)(ex));
|
|
432
333
|
throw ex;
|
|
433
334
|
}
|
|
434
335
|
|
|
@@ -455,7 +356,7 @@ const createHandler = params => {
|
|
|
455
356
|
}
|
|
456
357
|
} catch (ex) {
|
|
457
358
|
console.error(`Error while running the "RoutePlugin" ${routePluginName ? `(${routePluginName})` : ""} plugin in the beginning of the "createHandler" callable.`);
|
|
458
|
-
console.error(stringifyError(ex));
|
|
359
|
+
console.error((0, _stringifyError.stringifyError)(ex));
|
|
459
360
|
throw ex;
|
|
460
361
|
}
|
|
461
362
|
return app;
|
package/fastify.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_types","require","_fastify","_interopRequireDefault","_utils","_Context","_error","_RoutePlugin","_handlerClient","_cookie","_compress","_api","_BeforeHandlerPlugin","_HandlerResultPlugin","_HandlerErrorPlugin","_ModifyFastifyPlugin","_HandlerOnRequestPlugin","_ResponseHeaders","_ModifyResponseHeadersPlugin","createDefaultHeaders","ResponseHeaders","create","getWebinyVersionHeaders","getDefaultOptionsHeaders","getDefaultHeaders","routes","headers","keys","Object","all","every","key","length","set","allowedMethods","filter","type","Array","isArray","sort","join","stringifyError","error","name","message","code","stack","data","JSON","stringify","constructorName","constructor","process","env","DEBUG","modifyResponseHeaders","app","request","reply","modifyHeaders","webiny","plugins","byType","ModifyResponseHeadersPlugin","getHeaders","forEach","plugin","modify","createHandler","params","definedRoutes","POST","GET","OPTIONS","DELETE","PATCH","PUT","HEAD","COPY","LOCK","MKCOL","MOVE","PROPFIND","PROPPATCH","SEARCH","TRACE","UNLOCK","throwOnDefinedRoute","path","options","find","includes","console","WebinyError","override","addDefinedRoute","push","fastify","bodyLimit","disableRequestLogging","addHook","route","method","m","register","fastifyCookie","parseOptions","fastifyCompress","global","threshold","onUnsupportedEncoding","encoding","_","inflateIfDeflated","defined","onPost","handler","post","onGet","get","onOptions","onDelete","delete","onPatch","patch","onPut","put","onAll","onHead","head","context","PluginsContainer","createHandlerClient","merge","Context","WEBINY_VERSION","ex","decorate","isOptionsRequest","defaultHeaders","initialHeaders","HandlerOnRequestPlugin","result","exec","sent","explanation","send","hijack","ContextPlugin","apply","BeforeHandlerPlugin","preSerialization","__","payload","HandlerResultPlugin","handle","setErrorHandler","status","HandlerErrorPlugin","middleware","map","pl","next","benchmark","output","modifyPlugins","ModifyFastifyPlugin","modifyFastifyPluginName","routePlugins","RoutePlugin","routePluginName","cb","exports"],"sources":["fastify.ts"],"sourcesContent":["import { PluginCollection, PluginsContainer } from \"@webiny/plugins/types\";\nimport fastify, {\n FastifyInstance,\n FastifyServerOptions as ServerOptions,\n preSerializationAsyncHookHandler\n} from \"fastify\";\nimport { getWebinyVersionHeaders, middleware, MiddlewareCallable } from \"@webiny/utils\";\nimport {\n ContextRoutes,\n DefinedContextRoutes,\n HTTPMethods,\n Reply,\n Request,\n RouteMethodOptions\n} 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 { 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\";\nimport { ResponseHeaders } from \"~/ResponseHeaders\";\nimport { ModifyResponseHeadersPlugin } from \"~/plugins/ModifyResponseHeadersPlugin\";\n\nfunction createDefaultHeaders() {\n return ResponseHeaders.create({\n \"content-type\": \"application/json; charset=utf-8\",\n \"cache-control\": \"no-store\",\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}\n\nconst getDefaultOptionsHeaders = () => {\n return ResponseHeaders.create({\n \"access-control-max-age\": \"86400\",\n \"cache-control\": \"public, max-age=86400\"\n });\n};\n\nconst getDefaultHeaders = (routes: DefinedContextRoutes): ResponseHeaders => {\n const headers = createDefaultHeaders();\n\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 headers.set(\"access-control-allow-methods\", \"*\");\n } else {\n const allowedMethods = keys\n .filter(type => {\n if (!routes[type] || !Array.isArray(routes[type])) {\n return false;\n }\n return routes[type].length > 0;\n })\n .sort()\n .join(\",\");\n\n headers.set(\"access-control-allow-methods\", allowedMethods);\n }\n\n return headers;\n};\n\ninterface CustomError extends Error {\n code?: string;\n data?: Record<string, any>;\n}\n\nconst stringifyError = (error: CustomError) => {\n const { name, message, code, stack, data } = error;\n return JSON.stringify({\n ...error,\n constructorName: error.constructor?.name || \"UnknownError\",\n name: name || \"No error name\",\n message: message || \"No error message\",\n code: code || \"NO_CODE\",\n data,\n stack: process.env.DEBUG === \"true\" ? stack : \"Turn on the debug flag to see the stack.\"\n });\n};\n\nconst modifyResponseHeaders = (app: FastifyInstance, request: Request, reply: Reply) => {\n const modifyHeaders = app.webiny.plugins.byType<ModifyResponseHeadersPlugin>(\n ModifyResponseHeadersPlugin.type\n );\n\n const headers = ResponseHeaders.create(reply.getHeaders());\n\n modifyHeaders.forEach(plugin => {\n plugin.modify(request, headers);\n });\n\n reply.headers(headers.getHeaders());\n};\n\nexport interface CreateHandlerParams {\n plugins: PluginCollection | PluginsContainer;\n options?: ServerOptions;\n debug?: boolean;\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).find(key => {\n const routes = definedRoutes[key as HTTPMethods];\n return routes.includes(path);\n });\n if (!all) {\n return;\n }\n console.error(\n `Error while registering onAll route. One of the routes is already defined.`\n );\n console.error(JSON.stringify(all));\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 console.error(`Error while trying to override route: [${type}] ${path}`);\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 /**\n * We must attach the server to our internal context if we want to have it accessible.\n */\n const app = fastify({\n bodyLimit: 536870912, // 512MB\n disableRequestLogging: true,\n ...(params.options || {})\n });\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 let context: Context;\n\n const plugins = new PluginsContainer([\n /**\n * We must have handlerClient by default.\n * And it must be one of the first context plugins applied.\n */\n createHandlerClient()\n ]);\n plugins.merge(params.plugins || []);\n\n try {\n context = new Context({\n plugins,\n /**\n * Inserted via webpack at build time.\n */\n WEBINY_VERSION: process.env.WEBINY_VERSION as string,\n routes\n });\n } catch (ex) {\n console.error(`Error while constructing the Context.`);\n console.error(stringifyError(ex));\n throw ex;\n }\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 * 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 const isOptionsRequest = request.method === \"OPTIONS\";\n /**\n * Our default headers are always set. Users can override them.\n */\n const defaultHeaders = getDefaultHeaders(definedRoutes);\n\n const initialHeaders = isOptionsRequest\n ? defaultHeaders.merge(getDefaultOptionsHeaders())\n : defaultHeaders;\n\n reply.headers(initialHeaders.getHeaders());\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\n let name: string | undefined;\n try {\n for (const plugin of plugins) {\n name = plugin.name;\n const result = await plugin.exec(request, reply);\n if (result === false) {\n return;\n }\n }\n } catch (ex) {\n console.error(\n `Error while running the \"HandlerOnRequestPlugin\" ${\n name ? `(${name})` : \"\"\n } plugin in the onRequest hook.`\n );\n console.error(stringifyError(ex));\n throw ex;\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 (!isOptionsRequest) {\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.error(\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 modifyResponseHeaders(app, request, reply);\n\n reply.code(204).send(\"\").hijack();\n });\n\n app.addHook(\"preParsing\", async (request, reply) => {\n app.webiny.request = request;\n app.webiny.reply = reply;\n const plugins = app.webiny.plugins.byType<ContextPlugin>(ContextPlugin.type);\n let name: string | undefined;\n try {\n for (const plugin of plugins) {\n name = plugin.name;\n await plugin.apply(app.webiny);\n }\n } catch (ex) {\n console.error(\n `Error while running the \"ContextPlugin\" ${\n name ? `(${name})` : \"\"\n } plugin in the preParsing hook.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\n });\n /**\n *\n */\n app.addHook(\"preHandler\", async () => {\n const plugins = app.webiny.plugins.byType<BeforeHandlerPlugin>(BeforeHandlerPlugin.type);\n let name: string | undefined;\n try {\n for (const plugin of plugins) {\n name = plugin.name;\n await plugin.apply(app.webiny);\n }\n } catch (ex) {\n console.error(\n `Error while running the \"BeforeHandlerPlugin\" ${\n name ? `(${name})` : \"\"\n } plugin in the preHandler hook.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\n });\n\n /**\n *\n */\n const preSerialization: preSerializationAsyncHookHandler<any> = async (_, __, payload) => {\n const plugins = app.webiny.plugins.byType<HandlerResultPlugin>(HandlerResultPlugin.type);\n let name: string | undefined;\n try {\n for (const plugin of plugins) {\n name = plugin.name;\n await plugin.handle(app.webiny, payload);\n }\n } catch (ex) {\n console.error(\n `Error while running the \"HandlerResultPlugin\" ${\n name ? `(${name})` : \"\"\n } plugin in the preSerialization hook.`\n );\n console.error(stringifyError(ex));\n throw ex;\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 /**\n * When we are sending the error in the response, we cannot send the whole error object, as it might contain some sensitive data.\n */\n JSON.stringify({\n message: error.message,\n code: error.code,\n data: error.data\n })\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.error(\"@webiny/handler\");\n console.error(stringifyError(error));\n\n reply\n .status(500)\n .headers({\n \"Cache-Control\": \"no-store\"\n })\n .send(\n /**\n * When we are sending the error in the response, we cannot send the whole error object, as it might contain some sensitive data.\n */\n JSON.stringify({\n message: error.message,\n code: error.code,\n data: error.data\n })\n );\n\n const handler = middleware(\n plugins.map(pl => {\n return (context: Context, error: Error, next: MiddlewareCallable) => {\n return pl.handle(context, error, next);\n };\n })\n );\n await handler(app.webiny, error);\n\n return reply;\n });\n\n /**\n * Apply response headers modifier plugins.\n */\n app.addHook(\"onSend\", async (request, reply, payload) => {\n modifyResponseHeaders(app, request, reply);\n\n return payload;\n });\n\n /**\n * We need to output the benchmark results at the end of the request in both response and timeout cases\n */\n app.addHook(\"onResponse\", async () => {\n await context.benchmark.output();\n });\n\n app.addHook(\"onTimeout\", async () => {\n await context.benchmark.output();\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\n let modifyFastifyPluginName: string | undefined;\n try {\n for (const plugin of modifyPlugins) {\n modifyFastifyPluginName = plugin.name;\n plugin.modify(app);\n }\n } catch (ex) {\n console.error(\n `Error while running the \"ModifyFastifyPlugin\" ${\n modifyFastifyPluginName ? `(${modifyFastifyPluginName})` : \"\"\n } plugin in the end of the \"createHandler\" callable.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\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 let routePluginName: string | undefined;\n try {\n for (const plugin of routePlugins) {\n routePluginName = plugin.name;\n plugin.cb({\n ...app.webiny.routes,\n context: app.webiny\n });\n }\n } catch (ex) {\n console.error(\n `Error while running the \"RoutePlugin\" ${\n routePluginName ? `(${routePluginName})` : \"\"\n } plugin in the beginning of the \"createHandler\" callable.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\n\n return app;\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAC,sBAAA,CAAAF,OAAA;AAKA,IAAAG,MAAA,GAAAH,OAAA;AASA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAH,sBAAA,CAAAF,OAAA;AACA,IAAAM,YAAA,GAAAN,OAAA;AACA,IAAAO,cAAA,GAAAP,OAAA;AACA,IAAAQ,OAAA,GAAAN,sBAAA,CAAAF,OAAA;AACA,IAAAS,SAAA,GAAAP,sBAAA,CAAAF,OAAA;AACA,IAAAU,IAAA,GAAAV,OAAA;AACA,IAAAW,oBAAA,GAAAX,OAAA;AACA,IAAAY,oBAAA,GAAAZ,OAAA;AACA,IAAAa,mBAAA,GAAAb,OAAA;AACA,IAAAc,oBAAA,GAAAd,OAAA;AACA,IAAAe,uBAAA,GAAAf,OAAA;AACA,IAAAgB,gBAAA,GAAAhB,OAAA;AACA,IAAAiB,4BAAA,GAAAjB,OAAA;AAEA,SAASkB,oBAAoBA,CAAA,EAAG;EAC5B,OAAOC,gCAAe,CAACC,MAAM,CAAC;IAC1B,cAAc,EAAE,iCAAiC;IACjD,eAAe,EAAE,UAAU;IAC3B,6BAA6B,EAAE,GAAG;IAClC,8BAA8B,EAAE,GAAG;IACnC,8BAA8B,EAAE,mCAAmC;IACnE,GAAG,IAAAC,8BAAuB,EAAC;EAC/B,CAAC,CAAC;AACN;AAEA,MAAMC,wBAAwB,GAAGA,CAAA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ACD,cAAc,CAAC+F,EAAE,CAAC,CAAC;IACjC,MAAMA,EAAE;EACZ;EAEA,OAAOhF,GAAG;AACd,CAAC;AAACoH,OAAA,CAAAxG,aAAA,GAAAA,aAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_types","require","_fastify","_interopRequireDefault","_utils","_Context","_error","_RoutePlugin","_handlerClient","_cookie","_compress","_api","_BeforeHandlerPlugin","_HandlerResultPlugin","_HandlerErrorPlugin","_ModifyFastifyPlugin","_HandlerOnRequestPlugin","_ResponseHeaders","_ModifyResponseHeadersPlugin","_SetDefaultHeaders","_PreHandler","_stringifyError","_ProcessHandlerOnRequestPlugins","_ProcessContextPlugins","_IfNotOptionsRequest","_ProcessBeforeHandlerPlugins","_IfOptionsRequest","_SendEarlyOptionsResponse","modifyResponseHeaders","app","request","reply","modifyHeaders","webiny","plugins","byType","ModifyResponseHeadersPlugin","type","headers","ResponseHeaders","create","getHeaders","forEach","plugin","modify","createHandler","params","definedRoutes","POST","GET","OPTIONS","DELETE","PATCH","PUT","HEAD","COPY","LOCK","MKCOL","MOVE","PROPFIND","PROPPATCH","SEARCH","TRACE","UNLOCK","throwOnDefinedRoute","path","options","all","Object","keys","find","key","routes","includes","console","error","JSON","stringify","WebinyError","override","addDefinedRoute","push","fastify","bodyLimit","disableRequestLogging","addHook","route","method","Array","isArray","m","register","fastifyCookie","parseOptions","fastifyCompress","global","threshold","onUnsupportedEncoding","encoding","_","code","inflateIfDeflated","defined","onPost","handler","post","onGet","get","onOptions","onDelete","delete","onPatch","patch","onPut","put","onAll","onHead","head","context","PluginsContainer","createHandlerClient","merge","Context","WEBINY_VERSION","process","env","ex","stringifyError","decorate","body","undefined","handlerOnRequestPlugins","HandlerOnRequestPlugin","contextPlugins","ContextPlugin","beforeHandlerPlugins","BeforeHandlerPlugin","modifyHeadersPlugins","preHandler","PreHandler","SetDefaultHeaders","ProcessHandlerOnRequestPlugins","IfNotOptionsRequest","ProcessContextPlugins","ProcessBeforeHandlerPlugins","IfOptionsRequest","SendEarlyOptionsResponse","execute","__","payload","HandlerResultPlugin","name","handle","setErrorHandler","status","send","message","data","HandlerErrorPlugin","log","url","middleware","map","pl","next","benchmark","output","modifyPlugins","ModifyFastifyPlugin","modifyFastifyPluginName","routePlugins","RoutePlugin","routePluginName","cb","exports"],"sources":["fastify.ts"],"sourcesContent":["import { PluginCollection, PluginsContainer } from \"@webiny/plugins/types\";\nimport fastify, { FastifyInstance, FastifyServerOptions as ServerOptions } from \"fastify\";\nimport { middleware, MiddlewareCallable } from \"@webiny/utils\";\nimport {\n ContextRoutes,\n DefinedContextRoutes,\n HTTPMethods,\n Reply,\n Request,\n RouteMethodOptions\n} 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 { 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\";\nimport { ResponseHeaders } from \"~/ResponseHeaders\";\nimport { ModifyResponseHeadersPlugin } from \"~/plugins/ModifyResponseHeadersPlugin\";\nimport { SetDefaultHeaders } from \"./PreHandler/SetDefaultHeaders\";\nimport { PreHandler } from \"./PreHandler/PreHandler\";\nimport { stringifyError } from \"./stringifyError\";\nimport { ProcessHandlerOnRequestPlugins } from \"./PreHandler/ProcessHandlerOnRequestPlugins\";\nimport { ProcessContextPlugins } from \"./PreHandler/ProcessContextPlugins\";\nimport { IfNotOptionsRequest } from \"./PreHandler/IfNotOptionsRequest\";\nimport { ProcessBeforeHandlerPlugins } from \"./PreHandler/ProcessBeforeHandlerPlugins\";\nimport { IfOptionsRequest } from \"./PreHandler/IfOptionsRequest\";\nimport { SendEarlyOptionsResponse } from \"./PreHandler/SendEarlyOptionsResponse\";\n\nconst modifyResponseHeaders = (app: FastifyInstance, request: Request, reply: Reply) => {\n const modifyHeaders = app.webiny.plugins.byType<ModifyResponseHeadersPlugin>(\n ModifyResponseHeadersPlugin.type\n );\n\n const headers = ResponseHeaders.create(reply.getHeaders());\n\n modifyHeaders.forEach(plugin => {\n plugin.modify(request, headers);\n });\n\n reply.headers(headers.getHeaders());\n};\n\nexport interface CreateHandlerParams {\n plugins: PluginCollection | PluginsContainer;\n options?: ServerOptions;\n debug?: boolean;\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).find(key => {\n const routes = definedRoutes[key as HTTPMethods];\n return routes.includes(path);\n });\n if (!all) {\n return;\n }\n console.error(\n `Error while registering onAll route. One of the routes is already defined.`\n );\n console.error(JSON.stringify(all));\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 console.error(`Error while trying to override route: [${type}] ${path}`);\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 /**\n * We must attach the server to our internal context if we want to have it accessible.\n */\n const app = fastify({\n bodyLimit: 536870912, // 512MB\n disableRequestLogging: true,\n ...(params.options || {})\n });\n\n /**\n * We need to register routes in our system to output headers later on, and disallow route overriding.\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 let context: Context;\n\n const plugins = new PluginsContainer([\n /**\n * We must have handlerClient by default.\n * And it must be one of the first context plugins applied.\n */\n createHandlerClient()\n ]);\n plugins.merge(params.plugins || []);\n\n try {\n context = new Context({\n plugins,\n /**\n * Inserted via webpack at build time.\n */\n WEBINY_VERSION: process.env.WEBINY_VERSION as string,\n routes\n });\n } catch (ex) {\n console.error(`Error while constructing the Context.`);\n console.error(stringifyError(ex));\n throw ex;\n }\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 * With this we ensure that an undefined request body is not parsed on OPTIONS requests,\n * in case there's a `content-type` header set for whatever reason.\n *\n * @see https://fastify.dev/docs/latest/Reference/ContentTypeParser/#content-type-parser\n */\n app.addHook(\"onRequest\", async request => {\n if (request.method === \"OPTIONS\" && request.body === undefined) {\n request.headers[\"content-type\"] = undefined;\n }\n });\n\n /**\n * At this point, request body is properly parsed, and we can execute Webiny business logic.\n * - set default headers\n * - process `HandlerOnRequestPlugin`\n * - if OPTIONS request, exit early\n * - process `ContextPlugin`\n * - process `BeforeHandlerPlugin`\n */\n app.addHook(\"preHandler\", async (request, reply) => {\n app.webiny.request = request;\n app.webiny.reply = reply;\n\n const handlerOnRequestPlugins = app.webiny.plugins.byType<HandlerOnRequestPlugin>(\n HandlerOnRequestPlugin.type\n );\n\n const contextPlugins = app.webiny.plugins.byType<ContextPlugin>(ContextPlugin.type);\n\n const beforeHandlerPlugins = app.webiny.plugins.byType<BeforeHandlerPlugin>(\n BeforeHandlerPlugin.type\n );\n\n const modifyHeadersPlugins = app.webiny.plugins.byType<ModifyResponseHeadersPlugin>(\n ModifyResponseHeadersPlugin.type\n );\n\n const preHandler = new PreHandler([\n new SetDefaultHeaders(definedRoutes),\n new ProcessHandlerOnRequestPlugins(handlerOnRequestPlugins),\n new IfNotOptionsRequest([\n new ProcessContextPlugins(app.webiny, contextPlugins),\n new ProcessBeforeHandlerPlugins(app.webiny, beforeHandlerPlugins)\n ]),\n new IfOptionsRequest([new SendEarlyOptionsResponse(modifyHeadersPlugins)])\n ]);\n\n await preHandler.execute(request, reply);\n });\n\n app.addHook(\"preSerialization\", async (_, __, payload) => {\n const plugins = app.webiny.plugins.byType<HandlerResultPlugin>(HandlerResultPlugin.type);\n let name: string | undefined;\n try {\n for (const plugin of plugins) {\n name = plugin.name;\n await plugin.handle(app.webiny, payload);\n }\n } catch (ex) {\n console.error(\n `Error while running the \"HandlerResultPlugin\" ${\n name ? `(${name})` : \"\"\n } plugin in the preSerialization hook.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\n return payload;\n });\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 /**\n * When we are sending the error in the response, we cannot send the whole error object, as it might contain some sensitive data.\n */\n JSON.stringify({\n message: error.message,\n code: error.code,\n data: error.data\n })\n );\n });\n\n app.addHook(\"onError\", async (request, 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.error(\"@webiny/handler\");\n console.log({\n url: request.url,\n method: request.method,\n headers: request.headers,\n body: request.body\n });\n console.error(stringifyError(error));\n\n reply\n .status(500)\n .headers({\n \"Cache-Control\": \"no-store\"\n })\n .send(\n /**\n * When we are sending the error in the response, we cannot send the whole error object, as it might contain some sensitive data.\n */\n JSON.stringify({\n message: error.message,\n code: error.code,\n data: error.data\n })\n );\n\n const handler = middleware(\n plugins.map(pl => {\n return (context: Context, error: Error, next: MiddlewareCallable) => {\n return pl.handle(context, error, next);\n };\n })\n );\n await handler(app.webiny, error);\n\n return reply;\n });\n\n /**\n * Apply response headers modifier plugins.\n */\n app.addHook(\"onSend\", async (request, reply, payload) => {\n modifyResponseHeaders(app, request, reply);\n\n return payload;\n });\n\n /**\n * We need to output the benchmark results at the end of the request in both response and timeout cases\n */\n app.addHook(\"onResponse\", async () => {\n await context.benchmark.output();\n });\n\n app.addHook(\"onTimeout\", async () => {\n await context.benchmark.output();\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\n let modifyFastifyPluginName: string | undefined;\n try {\n for (const plugin of modifyPlugins) {\n modifyFastifyPluginName = plugin.name;\n plugin.modify(app);\n }\n } catch (ex) {\n console.error(\n `Error while running the \"ModifyFastifyPlugin\" ${\n modifyFastifyPluginName ? `(${modifyFastifyPluginName})` : \"\"\n } plugin in the end of the \"createHandler\" callable.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\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 let routePluginName: string | undefined;\n try {\n for (const plugin of routePlugins) {\n routePluginName = plugin.name;\n plugin.cb({\n ...app.webiny.routes,\n context: app.webiny\n });\n }\n } catch (ex) {\n console.error(\n `Error while running the \"RoutePlugin\" ${\n routePluginName ? `(${routePluginName})` : \"\"\n } plugin in the beginning of the \"createHandler\" callable.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\n\n return app;\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AASA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAH,sBAAA,CAAAF,OAAA;AACA,IAAAM,YAAA,GAAAN,OAAA;AACA,IAAAO,cAAA,GAAAP,OAAA;AACA,IAAAQ,OAAA,GAAA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;;EAE7E;AACJ;AACA;EACI,IAAIuI,eAAmC;EACvC,IAAI;IACA,KAAK,MAAMjI,MAAM,IAAI+H,YAAY,EAAE;MAC/BE,eAAe,GAAGjI,MAAM,CAAC4G,IAAI;MAC7B5G,MAAM,CAACkI,EAAE,CAAC;QACN,GAAGhJ,GAAG,CAACI,MAAM,CAACuC,MAAM;QACpB8C,OAAO,EAAEzF,GAAG,CAACI;MACjB,CAAC,CAAC;IACN;EACJ,CAAC,CAAC,OAAO6F,EAAE,EAAE;IACTpD,OAAO,CAACC,KAAK,CACT,yCACIiG,eAAe,GAAG,IAAIA,eAAe,GAAG,GAAG,EAAE,2DAErD,CAAC;IACDlG,OAAO,CAACC,KAAK,CAAC,IAAAoD,8BAAc,EAACD,EAAE,CAAC,CAAC;IACjC,MAAMA,EAAE;EACZ;EAEA,OAAOjG,GAAG;AACd,CAAC;AAACiJ,OAAA,CAAAjI,aAAA,GAAAA,aAAA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/handler",
|
|
3
|
-
"version": "5.42.0",
|
|
3
|
+
"version": "5.42.1-beta.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,16 +14,16 @@
|
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@fastify/compress": "6.2.0",
|
|
16
16
|
"@fastify/cookie": "8.3.0",
|
|
17
|
-
"@webiny/api": "5.42.0",
|
|
18
|
-
"@webiny/error": "5.42.0",
|
|
19
|
-
"@webiny/handler-client": "5.42.0",
|
|
20
|
-
"@webiny/plugins": "5.42.0",
|
|
21
|
-
"@webiny/utils": "5.42.0",
|
|
17
|
+
"@webiny/api": "5.42.1-beta.0",
|
|
18
|
+
"@webiny/error": "5.42.1-beta.0",
|
|
19
|
+
"@webiny/handler-client": "5.42.1-beta.0",
|
|
20
|
+
"@webiny/plugins": "5.42.1-beta.0",
|
|
21
|
+
"@webiny/utils": "5.42.1-beta.0",
|
|
22
22
|
"fastify": "4.15.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@webiny/cli": "5.42.0",
|
|
26
|
-
"@webiny/project-utils": "5.42.0",
|
|
25
|
+
"@webiny/cli": "5.42.1-beta.0",
|
|
26
|
+
"@webiny/project-utils": "5.42.1-beta.0",
|
|
27
27
|
"rimraf": "6.0.1",
|
|
28
28
|
"ttypescript": "1.5.15",
|
|
29
29
|
"typescript": "4.9.5"
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"build": "yarn webiny run build",
|
|
37
37
|
"watch": "yarn webiny run watch"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "16fb9009f44f242bbc8ba0e02c1d49b1f7ab935b"
|
|
40
40
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.stringifyError = void 0;
|
|
7
|
+
const stringifyError = error => {
|
|
8
|
+
const {
|
|
9
|
+
name,
|
|
10
|
+
message,
|
|
11
|
+
code,
|
|
12
|
+
stack,
|
|
13
|
+
data
|
|
14
|
+
} = error;
|
|
15
|
+
return JSON.stringify({
|
|
16
|
+
...error,
|
|
17
|
+
constructorName: error.constructor?.name || "UnknownError",
|
|
18
|
+
name: name || "No error name",
|
|
19
|
+
message: message || "No error message",
|
|
20
|
+
code: code || "NO_CODE",
|
|
21
|
+
data,
|
|
22
|
+
stack: process.env.DEBUG === "true" ? stack : "Turn on the debug flag to see the stack."
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
exports.stringifyError = stringifyError;
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=stringifyError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["stringifyError","error","name","message","code","stack","data","JSON","stringify","constructorName","constructor","process","env","DEBUG","exports"],"sources":["stringifyError.ts"],"sourcesContent":["export interface CustomError extends Error {\n code?: string;\n data?: Record<string, any>;\n}\n\nexport const stringifyError = (error: CustomError) => {\n const { name, message, code, stack, data } = error;\n return JSON.stringify({\n ...error,\n constructorName: error.constructor?.name || \"UnknownError\",\n name: name || \"No error name\",\n message: message || \"No error message\",\n code: code || \"NO_CODE\",\n data,\n stack: process.env.DEBUG === \"true\" ? stack : \"Turn on the debug flag to see the stack.\"\n });\n};\n"],"mappings":";;;;;;AAKO,MAAMA,cAAc,GAAIC,KAAkB,IAAK;EAClD,MAAM;IAAEC,IAAI;IAAEC,OAAO;IAAEC,IAAI;IAAEC,KAAK;IAAEC;EAAK,CAAC,GAAGL,KAAK;EAClD,OAAOM,IAAI,CAACC,SAAS,CAAC;IAClB,GAAGP,KAAK;IACRQ,eAAe,EAAER,KAAK,CAACS,WAAW,EAAER,IAAI,IAAI,cAAc;IAC1DA,IAAI,EAAEA,IAAI,IAAI,eAAe;IAC7BC,OAAO,EAAEA,OAAO,IAAI,kBAAkB;IACtCC,IAAI,EAAEA,IAAI,IAAI,SAAS;IACvBE,IAAI;IACJD,KAAK,EAAEM,OAAO,CAACC,GAAG,CAACC,KAAK,KAAK,MAAM,GAAGR,KAAK,GAAG;EAClD,CAAC,CAAC;AACN,CAAC;AAACS,OAAA,CAAAd,cAAA,GAAAA,cAAA","ignoreList":[]}
|