owebjs 1.1.5 → 1.1.6

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/dist/index.d.ts CHANGED
@@ -32,9 +32,25 @@ declare class _FastifyInstance {
32
32
  declare class Oweb extends _FastifyInstance {
33
33
  _options: OwebOptions;
34
34
  constructor(options?: OwebOptions);
35
+ /**
36
+ *
37
+ * Returns a fastify instance with the Oweb prototype methods
38
+ */
35
39
  setup(): Promise<Oweb>;
40
+ /**
41
+ *
42
+ * Loads routes from a directory
43
+ */
36
44
  loadRoutes({ directory }: LoadRoutesOptions): Promise<void>;
45
+ /**
46
+ *
47
+ * Sets the internal error handler
48
+ */
37
49
  setInternalErrorHandler(errorHandlerCallback: (request: FastifyRequest, reply: FastifyReply, error: Error) => void): void;
50
+ /**
51
+ *
52
+ * Starts the server
53
+ */
38
54
  start(options?: FastifyListenOptions): Promise<{
39
55
  err: Error;
40
56
  address: string;
@@ -23,28 +23,55 @@ class Oweb extends _FastifyInstance {
23
23
  });
24
24
  };
25
25
  }
26
+ /**
27
+ *
28
+ * Returns a fastify instance with the Oweb prototype methods
29
+ */
26
30
  async setup() {
27
31
  if (this._options.uWebSocketsEnabled) {
28
32
  const serverimp = (await import("../uwebsocket/server")).default;
29
33
  const server = await serverimp({});
30
- this._options.serverFactory = (handler, opts) => {
34
+ this._options.serverFactory = (handler) => {
31
35
  server.on("request", handler);
32
36
  return server;
33
37
  };
34
38
  }
35
- const fastifyInstance = Object.assign(this, Fastify(this._options));
36
- this.addHook("onRequest", (_, res, done) => {
39
+ const fastify = Fastify(this._options);
40
+ fastify.addHook("onRequest", (_, res, done) => {
37
41
  res.header("X-Powered-By", "Oweb");
38
42
  done();
39
43
  });
40
- return fastifyInstance;
44
+ for (const key in Object.getOwnPropertyDescriptors(Oweb.prototype)) {
45
+ if (key === "constructor")
46
+ continue;
47
+ Object.defineProperty(fastify, key, Object.getOwnPropertyDescriptor(Oweb.prototype, key));
48
+ }
49
+ Object.defineProperty(fastify, "_options", {
50
+ value: this._options,
51
+ writable: true,
52
+ enumerable: false,
53
+ configurable: false
54
+ });
55
+ return fastify;
41
56
  }
57
+ /**
58
+ *
59
+ * Loads routes from a directory
60
+ */
42
61
  loadRoutes({ directory }) {
43
- return assignRoutes(directory, this);
62
+ return assignRoutes(this, directory);
44
63
  }
64
+ /**
65
+ *
66
+ * Sets the internal error handler
67
+ */
45
68
  setInternalErrorHandler(errorHandlerCallback) {
46
69
  this._options.OWEB_INTERNAL_ERROR_HANDLER = errorHandlerCallback;
47
70
  }
71
+ /**
72
+ *
73
+ * Starts the server
74
+ */
48
75
  start(options = {
49
76
  port: 3e3,
50
77
  host: "127.0.0.1"
@@ -26,7 +26,7 @@ const generateRoutes = /* @__PURE__ */ __name(async (files) => {
26
26
  }
27
27
  return routes;
28
28
  }, "generateRoutes");
29
- const assignRoutes = /* @__PURE__ */ __name(async (directory, oweb) => {
29
+ const assignRoutes = /* @__PURE__ */ __name(async (oweb, directory) => {
30
30
  const files = await walk(directory);
31
31
  const routes = await generateRoutes(files);
32
32
  for (const route of routes) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "owebjs",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "description": "Flexible handler that built on top of Fastify",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",