@nattyjs/express 0.0.1-beta.3 → 0.0.1-beta.30

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.cjs CHANGED
@@ -55,42 +55,43 @@ function parseCookies(value) {
55
55
  return jsonCookies;
56
56
  }
57
57
 
58
- async function requestHandler(request, response) {
59
- const httpHandler = new core.HttpHandler();
60
- const httpContext = new core.HttpContext(
61
- {
62
- url: `http://localhost:3000${request.url}`,
63
- method: request.method,
64
- body: await getRequestBodyInfo(request),
65
- headers: request.headers,
66
- cookies: parseCookies(request.headers["cookie"])
67
- },
68
- response
69
- );
70
- return httpHandler.processRequest(httpContext).then((httpResponse) => {
71
- return getResponse(response, httpResponse);
72
- }).catch((t) => {
73
- response.send();
74
- });
58
+ function requestHandler(config) {
59
+ return async (request, response) => {
60
+ const httpHandler = new core.HttpHandler();
61
+ const url = config.framework == common.FrameworkType.Firebase ? `http://localhost:3000/api${request.url}` : `http://localhost:3000${request.url}`;
62
+ const httpContext = new core.HttpContext(
63
+ {
64
+ url,
65
+ method: request.method,
66
+ body: await getRequestBodyInfo(request),
67
+ headers: request.headers,
68
+ cookies: parseCookies(request.headers["cookie"])
69
+ },
70
+ response
71
+ );
72
+ return httpHandler.processRequest(httpContext).then((httpResponse) => {
73
+ return getResponse(response, httpResponse);
74
+ }).catch((t) => {
75
+ return getResponse(response, t.httpResponse);
76
+ });
77
+ };
75
78
  }
76
79
 
77
80
  const app = express__default();
78
81
  const ExpressModule = {
79
82
  init(config) {
80
83
  app.use(compression__default());
81
- app.use(cors__default({
82
- "origin": ["http://localhost:5173", "http://localhost:5174"],
83
- "methods": "GET,HEAD,PUT,PATCH,POST,DELETE",
84
- "preflightContinue": false,
85
- "optionsSuccessStatus": 204,
86
- "credentials": true
87
- }));
88
- app.use(express__default.json());
89
- app.all("*", requestHandler);
90
- if (config.autoGeneratePort == true)
91
- app.listen(3e3, () => {
92
- console.log("Server is running on port 3000 ");
84
+ if (config.cors)
85
+ app.use(cors__default(config.cors));
86
+ app.use(express__default.json({ limit: config.payload?.limit || "1mb" }));
87
+ app.all("*", requestHandler(config));
88
+ if (config.autoGeneratePort == true || config.autoGeneratePort == void 0)
89
+ common.getPort().then((port) => {
90
+ app.listen(port, () => {
91
+ console.log(`[NATTYJS]:Server is running on port ${port}`);
92
+ });
93
93
  });
94
+ return app;
94
95
  }
95
96
  };
96
97
 
package/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@ import express from 'express';
2
2
  import cors from 'cors';
3
3
  import compression from 'compression';
4
4
  import { HttpHandler, HttpContext } from '@nattyjs/core';
5
- import { GET } from '@nattyjs/common';
5
+ import { GET, FrameworkType, getPort } from '@nattyjs/common';
6
6
 
7
7
  async function getRequestBodyInfo(request) {
8
8
  const contentType = request.headers["content-type"];
@@ -47,42 +47,43 @@ function parseCookies(value) {
47
47
  return jsonCookies;
48
48
  }
49
49
 
50
- async function requestHandler(request, response) {
51
- const httpHandler = new HttpHandler();
52
- const httpContext = new HttpContext(
53
- {
54
- url: `http://localhost:3000${request.url}`,
55
- method: request.method,
56
- body: await getRequestBodyInfo(request),
57
- headers: request.headers,
58
- cookies: parseCookies(request.headers["cookie"])
59
- },
60
- response
61
- );
62
- return httpHandler.processRequest(httpContext).then((httpResponse) => {
63
- return getResponse(response, httpResponse);
64
- }).catch((t) => {
65
- response.send();
66
- });
50
+ function requestHandler(config) {
51
+ return async (request, response) => {
52
+ const httpHandler = new HttpHandler();
53
+ const url = config.framework == FrameworkType.Firebase ? `http://localhost:3000/api${request.url}` : `http://localhost:3000${request.url}`;
54
+ const httpContext = new HttpContext(
55
+ {
56
+ url,
57
+ method: request.method,
58
+ body: await getRequestBodyInfo(request),
59
+ headers: request.headers,
60
+ cookies: parseCookies(request.headers["cookie"])
61
+ },
62
+ response
63
+ );
64
+ return httpHandler.processRequest(httpContext).then((httpResponse) => {
65
+ return getResponse(response, httpResponse);
66
+ }).catch((t) => {
67
+ return getResponse(response, t.httpResponse);
68
+ });
69
+ };
67
70
  }
68
71
 
69
72
  const app = express();
70
73
  const ExpressModule = {
71
74
  init(config) {
72
75
  app.use(compression());
73
- app.use(cors({
74
- "origin": ["http://localhost:5173", "http://localhost:5174"],
75
- "methods": "GET,HEAD,PUT,PATCH,POST,DELETE",
76
- "preflightContinue": false,
77
- "optionsSuccessStatus": 204,
78
- "credentials": true
79
- }));
80
- app.use(express.json());
81
- app.all("*", requestHandler);
82
- if (config.autoGeneratePort == true)
83
- app.listen(3e3, () => {
84
- console.log("Server is running on port 3000 ");
76
+ if (config.cors)
77
+ app.use(cors(config.cors));
78
+ app.use(express.json({ limit: config.payload?.limit || "1mb" }));
79
+ app.all("*", requestHandler(config));
80
+ if (config.autoGeneratePort == true || config.autoGeneratePort == void 0)
81
+ getPort().then((port) => {
82
+ app.listen(port, () => {
83
+ console.log(`[NATTYJS]:Server is running on port ${port}`);
84
+ });
85
85
  });
86
+ return app;
86
87
  }
87
88
  };
88
89
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nattyjs/express",
3
- "version": "0.0.1-beta.3",
3
+ "version": "0.0.1-beta.30",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "ajayojha <ojhaajay@outlook.com>",
@@ -18,8 +18,9 @@
18
18
  "express": "4.18.2",
19
19
  "cors": "2.8.5",
20
20
  "compression": "1.7.4",
21
- "@nattyjs/core": "0.0.1-beta.3",
22
- "@nattyjs/types": "0.0.1-beta.3"
21
+ "@nattyjs/core": "0.0.1-beta.30",
22
+ "@nattyjs/common": "0.0.1-beta.30",
23
+ "@nattyjs/types": "0.0.1-beta.30"
23
24
  },
24
25
  "devDependencies": {
25
26
  "@types/node": "20.3.1",