@opra/http 1.0.0-beta.4 → 1.0.0-beta.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.
@@ -9,7 +9,6 @@ const http_adapter_js_1 = require("./http-adapter.js");
9
9
  const http_context_js_1 = require("./http-context.js");
10
10
  const http_incoming_interface_js_1 = require("./interfaces/http-incoming.interface.js");
11
11
  const http_outgoing_interface_js_1 = require("./interfaces/http-outgoing.interface.js");
12
- const wrap_exception_js_1 = require("./utils/wrap-exception.js");
13
12
  class ExpressAdapter extends http_adapter_js_1.HttpAdapter {
14
13
  constructor(app, document, options) {
15
14
  super(document, options);
@@ -19,7 +18,7 @@ class ExpressAdapter extends http_adapter_js_1.HttpAdapter {
19
18
  throw new TypeError('document.api must be instance of HttpApi');
20
19
  for (const c of this.api.controllers.values())
21
20
  this._createControllers(c);
22
- this._initRouter(options?.basePath);
21
+ this._initRouter();
23
22
  }
24
23
  get platform() {
25
24
  return 'express';
@@ -33,18 +32,6 @@ class ExpressAdapter extends http_adapter_js_1.HttpAdapter {
33
32
  await processInstance(subResource);
34
33
  }
35
34
  }
36
- if (controller.onShutdown) {
37
- const instance = this._controllerInstances.get(controller) || controller.instance;
38
- if (instance) {
39
- try {
40
- await controller.onShutdown.call(instance, controller);
41
- }
42
- catch (e) {
43
- if (this.listenerCount('error'))
44
- this.emit('error', (0, wrap_exception_js_1.wrapException)(e));
45
- }
46
- }
47
- }
48
35
  };
49
36
  for (const c of this.api.controllers.values())
50
37
  await processInstance(c);
@@ -54,16 +41,9 @@ class ExpressAdapter extends http_adapter_js_1.HttpAdapter {
54
41
  const controller = this.api.findController(controllerPath);
55
42
  return controller && this._controllerInstances.get(controller);
56
43
  }
57
- _initRouter(basePath) {
44
+ _initRouter() {
58
45
  const router = (0, express_1.Router)();
59
- if (basePath) {
60
- if (!basePath.startsWith('/'))
61
- basePath = '/' + basePath;
62
- if (basePath)
63
- this.app.use(basePath, router);
64
- }
65
- else
66
- this.app.use(router);
46
+ this.app.use(this.basePath, router);
67
47
  const createContext = async (_req, _res, args) => {
68
48
  const request = http_incoming_interface_js_1.HttpIncoming.from(_req);
69
49
  const response = http_outgoing_interface_js_1.HttpOutgoing.from(_res);
@@ -141,8 +121,6 @@ class ExpressAdapter extends http_adapter_js_1.HttpAdapter {
141
121
  if (!instance && controller.ctor)
142
122
  instance = new controller.ctor();
143
123
  if (instance) {
144
- if (typeof controller.onInit === 'function')
145
- controller.onInit.call(instance, controller);
146
124
  this._controllerInstances.set(controller, instance);
147
125
  // Initialize sub resources
148
126
  for (const r of controller.controllers.values()) {
@@ -16,6 +16,9 @@ class HttpAdapter extends core_1.PlatformAdapter {
16
16
  throw new TypeError(`The document does not expose an HTTP Api`);
17
17
  this.handler = new http_handler_js_1.HttpHandler(this);
18
18
  this.interceptors = [...(options?.interceptors || [])];
19
+ this.basePath = options?.basePath || '/';
20
+ if (!this.basePath.startsWith('/'))
21
+ this.basePath = '/' + this.basePath;
19
22
  }
20
23
  get api() {
21
24
  return this.document.httpApi;
@@ -10,7 +10,7 @@ const node_path_1 = tslib_1.__importDefault(require("node:path"));
10
10
  const common_1 = require("@opra/common");
11
11
  const content_disposition_1 = tslib_1.__importDefault(require("content-disposition"));
12
12
  const content_type_1 = tslib_1.__importDefault(require("content-type"));
13
- const cookie_1 = tslib_1.__importDefault(require("cookie"));
13
+ const cookie = tslib_1.__importStar(require("cookie"));
14
14
  const cookie_signature_1 = tslib_1.__importDefault(require("cookie-signature"));
15
15
  const encodeurl_1 = tslib_1.__importDefault(require("encodeurl"));
16
16
  const mime_types_1 = tslib_1.__importDefault(require("mime-types"));
@@ -79,7 +79,7 @@ class HttpOutgoingHost {
79
79
  }
80
80
  if (opts.path == null)
81
81
  opts.path = '/';
82
- this.appendHeader('Set-Cookie', cookie_1.default.serialize(name, String(val), opts));
82
+ this.appendHeader('Set-Cookie', cookie.serialize(name, String(val), opts));
83
83
  return this;
84
84
  }
85
85
  status(code) {
@@ -5,7 +5,6 @@ import { HttpAdapter } from './http-adapter.js';
5
5
  import { HttpContext } from './http-context.js';
6
6
  import { HttpIncoming } from './interfaces/http-incoming.interface.js';
7
7
  import { HttpOutgoing } from './interfaces/http-outgoing.interface.js';
8
- import { wrapException } from './utils/wrap-exception.js';
9
8
  export class ExpressAdapter extends HttpAdapter {
10
9
  constructor(app, document, options) {
11
10
  super(document, options);
@@ -15,7 +14,7 @@ export class ExpressAdapter extends HttpAdapter {
15
14
  throw new TypeError('document.api must be instance of HttpApi');
16
15
  for (const c of this.api.controllers.values())
17
16
  this._createControllers(c);
18
- this._initRouter(options?.basePath);
17
+ this._initRouter();
19
18
  }
20
19
  get platform() {
21
20
  return 'express';
@@ -29,18 +28,6 @@ export class ExpressAdapter extends HttpAdapter {
29
28
  await processInstance(subResource);
30
29
  }
31
30
  }
32
- if (controller.onShutdown) {
33
- const instance = this._controllerInstances.get(controller) || controller.instance;
34
- if (instance) {
35
- try {
36
- await controller.onShutdown.call(instance, controller);
37
- }
38
- catch (e) {
39
- if (this.listenerCount('error'))
40
- this.emit('error', wrapException(e));
41
- }
42
- }
43
- }
44
31
  };
45
32
  for (const c of this.api.controllers.values())
46
33
  await processInstance(c);
@@ -50,16 +37,9 @@ export class ExpressAdapter extends HttpAdapter {
50
37
  const controller = this.api.findController(controllerPath);
51
38
  return controller && this._controllerInstances.get(controller);
52
39
  }
53
- _initRouter(basePath) {
40
+ _initRouter() {
54
41
  const router = Router();
55
- if (basePath) {
56
- if (!basePath.startsWith('/'))
57
- basePath = '/' + basePath;
58
- if (basePath)
59
- this.app.use(basePath, router);
60
- }
61
- else
62
- this.app.use(router);
42
+ this.app.use(this.basePath, router);
63
43
  const createContext = async (_req, _res, args) => {
64
44
  const request = HttpIncoming.from(_req);
65
45
  const response = HttpOutgoing.from(_res);
@@ -137,8 +117,6 @@ export class ExpressAdapter extends HttpAdapter {
137
117
  if (!instance && controller.ctor)
138
118
  instance = new controller.ctor();
139
119
  if (instance) {
140
- if (typeof controller.onInit === 'function')
141
- controller.onInit.call(instance, controller);
142
120
  this._controllerInstances.set(controller, instance);
143
121
  // Initialize sub resources
144
122
  for (const r of controller.controllers.values()) {
@@ -13,6 +13,9 @@ export class HttpAdapter extends PlatformAdapter {
13
13
  throw new TypeError(`The document does not expose an HTTP Api`);
14
14
  this.handler = new HttpHandler(this);
15
15
  this.interceptors = [...(options?.interceptors || [])];
16
+ this.basePath = options?.basePath || '/';
17
+ if (!this.basePath.startsWith('/'))
18
+ this.basePath = '/' + this.basePath;
16
19
  }
17
20
  get api() {
18
21
  return this.document.httpApi;
@@ -6,7 +6,7 @@ import path from 'node:path';
6
6
  import { HttpStatusCode } from '@opra/common';
7
7
  import contentDisposition from 'content-disposition';
8
8
  import contentType from 'content-type';
9
- import cookie from 'cookie';
9
+ import * as cookie from 'cookie';
10
10
  import cookieSignature from 'cookie-signature';
11
11
  import encodeUrl from 'encodeurl';
12
12
  import mime from 'mime-types';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/http",
3
- "version": "1.0.0-beta.4",
3
+ "version": "1.0.0-beta.6",
4
4
  "description": "Opra Http Server Adapter",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -8,15 +8,15 @@
8
8
  "@browsery/antlr4": "^4.13.3-r1",
9
9
  "@browsery/http-parser": "^0.5.9-r1",
10
10
  "@browsery/type-is": "^1.6.18-r5",
11
- "@opra/common": "^1.0.0-beta.4",
12
- "@opra/core": "^1.0.0-beta.4",
11
+ "@opra/common": "^1.0.0-beta.6",
12
+ "@opra/core": "^1.0.0-beta.6",
13
13
  "accepts": "^1.3.8",
14
14
  "base64-stream": "^1.0.0",
15
15
  "busboy": "^1.6.0",
16
16
  "bytes": "^3.1.2",
17
17
  "content-disposition": "^0.5.4",
18
18
  "content-type": "^1.0.5",
19
- "cookie": "^0.6.0",
19
+ "cookie": "^1.0.0",
20
20
  "cookie-signature": "^1.2.1",
21
21
  "cppzst": "^2.0.12",
22
22
  "encodeurl": "^2.0.0",
@@ -8,6 +8,6 @@ export declare class ExpressAdapter extends HttpAdapter {
8
8
  get platform(): string;
9
9
  close(): Promise<void>;
10
10
  getControllerInstance<T>(controllerPath: string): T | undefined;
11
- protected _initRouter(basePath?: string): void;
11
+ protected _initRouter(): void;
12
12
  protected _createControllers(controller: HttpController): void;
13
13
  }
@@ -26,6 +26,7 @@ export declare namespace HttpAdapter {
26
26
  export declare abstract class HttpAdapter extends PlatformAdapter {
27
27
  readonly handler: HttpHandler;
28
28
  readonly protocol: OpraSchema.Transport;
29
+ readonly basePath: string;
29
30
  interceptors: (HttpAdapter.InterceptorFunction | HttpAdapter.IHttpInterceptor)[];
30
31
  protected constructor(document: ApiDocument, options?: HttpAdapter.Options);
31
32
  get api(): HttpApi;