@wxn0brp/falcon-frame 0.5.7 → 0.5.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -97,7 +97,7 @@ app.post("/logout", (req, res) => {
97
97
  });
98
98
 
99
99
  // if no route matches
100
- app.all("*", (req, res) => {
100
+ app.set404((req, res) => {
101
101
  res.status(404).json({ error: "Not found" });
102
102
  });
103
103
 
package/dist/index.d.ts CHANGED
@@ -16,12 +16,14 @@ export declare class FalconFrame<Vars extends Record<string, any> = any> extends
16
16
  vars: Vars;
17
17
  opts: Opts;
18
18
  engines: Record<string, EngineCallback>;
19
+ _404: RouteHandler;
19
20
  constructor(opts?: Partial<Opts>);
20
21
  addBodyParser(parser: RouteHandler): this;
21
22
  listen(port: number | string, callback?: (() => void) | boolean, beforeHandleRequest?: BeforeHandleRequest): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
22
23
  getApp(beforeHandleRequest?: BeforeHandleRequest): (req: any, res: any) => Promise<void>;
23
24
  engine(ext: string, callback: EngineCallback): this;
24
25
  setVar(key: keyof Vars, value: typeof this.vars[keyof Vars]): void;
26
+ set(key: keyof Vars, value: typeof this.vars[keyof Vars]): void;
25
27
  getVar(key: string): typeof this.vars[keyof Vars];
26
28
  /**
27
29
  * Sets the allowed origins for CORS.
@@ -38,6 +40,7 @@ export declare class FalconFrame<Vars extends Record<string, any> = any> extends
38
40
  * @returns The server object returned by the listen method.
39
41
  */
40
42
  l(port: number): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
43
+ set404(handler: RouteHandler): void;
41
44
  }
42
45
  export default FalconFrame;
43
46
  export * as Helpers from "./helpers.js";
package/dist/index.js CHANGED
@@ -12,6 +12,9 @@ export class FalconFrame extends Router {
12
12
  vars = {};
13
13
  opts = {};
14
14
  engines = {};
15
+ _404 = (req, res) => {
16
+ res.end("404: File had second thoughts");
17
+ };
15
18
  constructor(opts = {}) {
16
19
  super();
17
20
  const loggerOpts = opts?.loggerOpts || {};
@@ -89,6 +92,10 @@ export class FalconFrame extends Router {
89
92
  // @ts-ignore
90
93
  this.vars[key] = value;
91
94
  }
95
+ set(key, value) {
96
+ // @ts-ignore
97
+ this.vars[key] = value;
98
+ }
92
99
  getVar(key) {
93
100
  // @ts-ignore
94
101
  return this.vars[key];
@@ -112,6 +119,9 @@ export class FalconFrame extends Router {
112
119
  l(port) {
113
120
  return this.listen(+process.env.PORT || port, true);
114
121
  }
122
+ set404(handler) {
123
+ this._404 = handler;
124
+ }
115
125
  }
116
126
  export default FalconFrame;
117
127
  export * as Helpers from "./helpers.js";
package/dist/req.js CHANGED
@@ -36,13 +36,16 @@ export function handleRequest(req, res, FF) {
36
36
  logger.debug("Matched middlewares: " +
37
37
  matchedMiddlewares.map((middleware) => middleware.path).join(", "));
38
38
  if (matchedMiddlewares.length === 0) {
39
- res.status(404).end("404: File had second thoughts");
39
+ res.status(404);
40
+ FF._404(req, res);
40
41
  return;
41
42
  }
42
43
  let middlewareIndex = 0;
43
44
  async function next() {
44
45
  if (middlewareIndex >= matchedMiddlewares.length) {
45
- return res.status(404).end("404: File had second thoughts");
46
+ res.status(404);
47
+ FF._404(req, res);
48
+ return;
46
49
  }
47
50
  const middleware = matchedMiddlewares[middlewareIndex++];
48
51
  logger.debug(`Executing middleware ${middlewareIndex} of ${matchedMiddlewares.length} matched for path [${middleware.path}]`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/falcon-frame",
3
- "version": "0.5.7",
3
+ "version": "0.5.8",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "author": "wxn0brP",