@jayfong/x-server 1.16.1 → 1.17.0

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/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [1.17.0](https://github.com/jfWorks/x-server/compare/v1.16.1...v1.17.0) (2022-04-27)
6
+
7
+
8
+ ### Features
9
+
10
+ * add ctx.url ([1092009](https://github.com/jfWorks/x-server/commit/10920094646e975e74dc0339ecc290e257f3ca52))
11
+
5
12
  ### [1.16.1](https://github.com/jfWorks/x-server/compare/v1.16.0...v1.16.1) (2022-04-27)
6
13
 
7
14
 
@@ -87,13 +87,20 @@ class Server {
87
87
  const handlerMethod = handlerOptions.requestMethod || 'POST';
88
88
  const isWS = handlerMethod === 'WS';
89
89
  const serverMethod = isWS ? 'GET' : _http_method.HandlerMethodToHttpMethod[handlerMethod];
90
+
91
+ const appUrl = _x.x.env.APP_URL.replace(/\/+$/, '');
92
+
90
93
  this.fastify.route({
91
94
  method: serverMethod,
92
95
  url: item.path,
93
96
  websocket: isWS,
94
97
  handler: async (req, res) => {
98
+ const url = `${appUrl}${// 结构:/test/sss?x=2
99
+ req.url}`;
100
+
95
101
  if (isWS) {
96
102
  await item.handler.handle(undefined, {
103
+ url: url,
97
104
  headers: req.headers,
98
105
  redirect: undefined,
99
106
  ws: req
@@ -120,6 +127,7 @@ class Server {
120
127
  ...req.body,
121
128
  ...files
122
129
  }, {
130
+ url: url,
123
131
  headers: req.headers,
124
132
  redirect: url => res.redirect(url),
125
133
  ws: undefined
@@ -74,13 +74,18 @@ export class Server {
74
74
  const handlerMethod = handlerOptions.requestMethod || 'POST';
75
75
  const isWS = handlerMethod === 'WS';
76
76
  const serverMethod = isWS ? 'GET' : HandlerMethodToHttpMethod[handlerMethod];
77
+ const appUrl = x.env.APP_URL.replace(/\/+$/, '');
77
78
  this.fastify.route({
78
79
  method: serverMethod,
79
80
  url: item.path,
80
81
  websocket: isWS,
81
82
  handler: async (req, res) => {
83
+ const url = `${appUrl}${// 结构:/test/sss?x=2
84
+ req.url}`;
85
+
82
86
  if (isWS) {
83
87
  await item.handler.handle(undefined, {
88
+ url: url,
84
89
  headers: req.headers,
85
90
  redirect: undefined,
86
91
  ws: req
@@ -107,6 +112,7 @@ export class Server {
107
112
  ...req.body,
108
113
  ...files
109
114
  }, {
115
+ url: url,
110
116
  headers: req.headers,
111
117
  redirect: url => res.redirect(url),
112
118
  ws: undefined
@@ -45,6 +45,10 @@ export declare namespace XHandler {
45
45
  interface ExtraContext {
46
46
  }
47
47
  interface Context extends ExtraContext {
48
+ /**
49
+ * 当前请求的地址
50
+ */
51
+ url: string;
48
52
  /**
49
53
  * 请求头
50
54
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "1.16.1",
3
+ "version": "1.17.0",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",