remult 0.14.15 → 0.14.19

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.
@@ -38,7 +38,28 @@ class middleware {
38
38
  return route;
39
39
  }
40
40
  handleRequest(req, res, next) {
41
- let lowerPath = req.path.toLowerCase();
41
+ let theUrl = req.url;
42
+ if (theUrl.startsWith('/')) //next sends a partial url '/api/tasks' and not the full url
43
+ theUrl = 'http:' + theUrl;
44
+ const url = new URL(theUrl);
45
+ const path = url.pathname;
46
+ if (!req.query) {
47
+ let query = {};
48
+ url.searchParams.forEach((val, key) => {
49
+ let current = query[key];
50
+ if (!current) {
51
+ query[key] = val;
52
+ return;
53
+ }
54
+ if (Array.isArray(current)) {
55
+ current.push(val);
56
+ return;
57
+ }
58
+ query[key] = [current, val];
59
+ });
60
+ req.query = query;
61
+ }
62
+ let lowerPath = path.toLowerCase();
42
63
  let m = this.map.get(lowerPath);
43
64
  if (m) {
44
65
  let h = m.get(req.method.toLowerCase());
@@ -47,14 +68,16 @@ class middleware {
47
68
  return;
48
69
  }
49
70
  }
50
- let idPosition = req.path.lastIndexOf('/');
71
+ let idPosition = path.lastIndexOf('/');
51
72
  if (idPosition >= 0) {
52
- lowerPath = req.path.substring(0, idPosition) + '/:id';
73
+ lowerPath = path.substring(0, idPosition) + '/:id';
53
74
  m = this.map.get(lowerPath);
54
75
  if (m) {
55
76
  let h = m.get(req.method.toLowerCase());
56
77
  if (h) {
57
- req.params.id = req.path.substring(idPosition + 1);
78
+ if (!req.params)
79
+ req.params = {};
80
+ req.params.id = path.substring(idPosition + 1);
58
81
  h(req, res, next);
59
82
  return;
60
83
  }
@@ -32,11 +32,10 @@ export interface RemultExpressBridge extends GenericRequestHandler {
32
32
  }
33
33
  export interface GenericRequest {
34
34
  method: any;
35
- path: any;
36
- originalUrl: any;
37
- query: any;
35
+ url: any;
36
+ query?: any;
38
37
  body: any;
39
- params: any;
38
+ params?: any;
40
39
  }
41
40
  export interface GenericResponse {
42
41
  json(data: any): any;
@@ -505,7 +505,7 @@ class ExpressResponseBridgeToDataApiResponse {
505
505
  console.error({
506
506
  message: data.message,
507
507
  stack: data.stack?.split('\n'),
508
- url: this.req.originalUrl ?? this.req.path,
508
+ url: this.req.url,
509
509
  method: this.req.method
510
510
  });
511
511
  this.r.statusCode = 400;
@@ -3,7 +3,7 @@ import axios from 'axios';
3
3
  import { HttpProviderBridgeToRestDataProviderHttpProvider, Remult } from '../context';
4
4
  import { Entity, Fields } from '../remult3';
5
5
  import { Action, BackendMethod } from '../server-action';
6
- Remult.apiBaseUrl = 'http://localhost:3001/api';
6
+ Remult.apiBaseUrl = 'http://localhost:8000/api';
7
7
  const path = Remult.apiBaseUrl + '/tasks';
8
8
  fit("works", async () => {
9
9
  const repo = await create3Tasks();
@@ -61,7 +61,7 @@ fit("test http 404", async () => {
61
61
  expect(error.response.status).toBe(404);
62
62
  });
63
63
  fit("test http 201", async () => {
64
- let result = await axios.post('http://localhost:3001/api/tasks', { title: "z", id: "" });
64
+ let result = await axios.post(path, { title: "z", id: "" });
65
65
  expect(result.data.title).toBe("z");
66
66
  expect(result.status).toBe(201);
67
67
  result = await axios.delete(path + "/" + result.data.id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "0.14.15",
3
+ "version": "0.14.19",
4
4
  "description": "A CRUD framework for full-stack TypeScript",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -42,7 +42,28 @@ var middleware = /** @class */ (function () {
42
42
  return route;
43
43
  };
44
44
  middleware.prototype.handleRequest = function (req, res, next) {
45
- var lowerPath = req.path.toLowerCase();
45
+ var theUrl = req.url;
46
+ if (theUrl.startsWith('/')) //next sends a partial url '/api/tasks' and not the full url
47
+ theUrl = 'http:' + theUrl;
48
+ var url = new URL(theUrl);
49
+ var path = url.pathname;
50
+ if (!req.query) {
51
+ var query_1 = {};
52
+ url.searchParams.forEach(function (val, key) {
53
+ var current = query_1[key];
54
+ if (!current) {
55
+ query_1[key] = val;
56
+ return;
57
+ }
58
+ if (Array.isArray(current)) {
59
+ current.push(val);
60
+ return;
61
+ }
62
+ query_1[key] = [current, val];
63
+ });
64
+ req.query = query_1;
65
+ }
66
+ var lowerPath = path.toLowerCase();
46
67
  var m = this.map.get(lowerPath);
47
68
  if (m) {
48
69
  var h = m.get(req.method.toLowerCase());
@@ -51,14 +72,16 @@ var middleware = /** @class */ (function () {
51
72
  return;
52
73
  }
53
74
  }
54
- var idPosition = req.path.lastIndexOf('/');
75
+ var idPosition = path.lastIndexOf('/');
55
76
  if (idPosition >= 0) {
56
- lowerPath = req.path.substring(0, idPosition) + '/:id';
77
+ lowerPath = path.substring(0, idPosition) + '/:id';
57
78
  m = this.map.get(lowerPath);
58
79
  if (m) {
59
80
  var h = m.get(req.method.toLowerCase());
60
81
  if (h) {
61
- req.params.id = req.path.substring(idPosition + 1);
82
+ if (!req.params)
83
+ req.params = {};
84
+ req.params.id = path.substring(idPosition + 1);
62
85
  h(req, res, next);
63
86
  return;
64
87
  }
@@ -32,11 +32,10 @@ export interface RemultExpressBridge extends GenericRequestHandler {
32
32
  }
33
33
  export interface GenericRequest {
34
34
  method: any;
35
- path: any;
36
- originalUrl: any;
37
- query: any;
35
+ url: any;
36
+ query?: any;
38
37
  body: any;
39
- params: any;
38
+ params?: any;
40
39
  }
41
40
  export interface GenericResponse {
42
41
  json(data: any): any;
@@ -599,12 +599,12 @@ var ExpressResponseBridgeToDataApiResponse = /** @class */ (function () {
599
599
  this.sendStatus(404);
600
600
  };
601
601
  ExpressResponseBridgeToDataApiResponse.prototype.error = function (data) {
602
- var _a, _b;
602
+ var _a;
603
603
  data = data_api_1.serializeError(data);
604
604
  console.error({
605
605
  message: data.message,
606
606
  stack: (_a = data.stack) === null || _a === void 0 ? void 0 : _a.split('\n'),
607
- url: (_b = this.req.originalUrl) !== null && _b !== void 0 ? _b : this.req.path,
607
+ url: this.req.url,
608
608
  method: this.req.method
609
609
  });
610
610
  this.r.statusCode = 400;
@@ -6,7 +6,7 @@ var axios_1 = require("axios");
6
6
  var context_1 = require("../context");
7
7
  var remult3_1 = require("../remult3");
8
8
  var server_action_1 = require("../server-action");
9
- context_1.Remult.apiBaseUrl = 'http://localhost:3001/api';
9
+ context_1.Remult.apiBaseUrl = 'http://localhost:8000/api';
10
10
  var path = context_1.Remult.apiBaseUrl + '/tasks';
11
11
  fit("works", function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
12
12
  var repo, tasks, _a;
@@ -138,7 +138,7 @@ fit("test http 201", function () { return tslib_1.__awaiter(void 0, void 0, void
138
138
  var result;
139
139
  return tslib_1.__generator(this, function (_a) {
140
140
  switch (_a.label) {
141
- case 0: return [4 /*yield*/, axios_1.default.post('http://localhost:3001/api/tasks', { title: "z", id: "" })];
141
+ case 0: return [4 /*yield*/, axios_1.default.post(path, { title: "z", id: "" })];
142
142
  case 1:
143
143
  result = _a.sent();
144
144
  expect(result.data.title).toBe("z");