@h3ravel/http 11.0.0 → 11.1.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/README.md +13 -1
- package/dist/index.cjs +325 -366
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +192 -184
- package/dist/index.d.ts +192 -184
- package/dist/index.js +292 -340
- package/dist/index.js.map +1 -1
- package/dist/stubs/controller-resource.stub +34 -0
- package/dist/stubs/controller.stub +3 -0
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -1,393 +1,352 @@
|
|
|
1
|
-
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
8
|
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
18
17
|
};
|
|
19
|
-
var
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
Request: () => Request,
|
|
31
|
-
Response: () => Response
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(index_exports);
|
|
23
|
+
//#endregion
|
|
24
|
+
let __h3ravel_shared = require("@h3ravel/shared");
|
|
25
|
+
__h3ravel_shared = __toESM(__h3ravel_shared);
|
|
26
|
+
let h3 = require("h3");
|
|
27
|
+
h3 = __toESM(h3);
|
|
28
|
+
let __h3ravel_core = require("@h3ravel/core");
|
|
29
|
+
__h3ravel_core = __toESM(__h3ravel_core);
|
|
30
|
+
let __h3ravel_support = require("@h3ravel/support");
|
|
31
|
+
__h3ravel_support = __toESM(__h3ravel_support);
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
var
|
|
33
|
+
//#region src/Middleware.ts
|
|
34
|
+
var Middleware = class {};
|
|
37
35
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
static {
|
|
41
|
-
__name(this, "Middleware");
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
// src/Middleware/LogRequests.ts
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/Middleware/LogRequests.ts
|
|
46
38
|
var LogRequests = class extends Middleware {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
console.log(`[${request.getEvent("method")}] ${url.pathname + url.search}`);
|
|
53
|
-
return next();
|
|
54
|
-
}
|
|
39
|
+
async handle({ request }, next) {
|
|
40
|
+
const url = request.getEvent("url");
|
|
41
|
+
console.log(`[${request.getEvent("method")}] ${url.pathname + url.search}`);
|
|
42
|
+
return next();
|
|
43
|
+
}
|
|
55
44
|
};
|
|
56
45
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/Providers/HttpServiceProvider.ts
|
|
48
|
+
/**
|
|
49
|
+
* Sets up HTTP kernel and request lifecycle.
|
|
50
|
+
*
|
|
51
|
+
* Register Request, Response, and Middleware classes.
|
|
52
|
+
* Configure global middleware stack.
|
|
53
|
+
* Boot HTTP kernel.
|
|
54
|
+
*
|
|
55
|
+
* Auto-Registered
|
|
56
|
+
*/
|
|
57
|
+
var HttpServiceProvider = class extends __h3ravel_core.ServiceProvider {
|
|
58
|
+
static priority = 998;
|
|
59
|
+
register() {
|
|
60
|
+
this.app.singleton("http.app", () => {
|
|
61
|
+
return new h3.H3();
|
|
62
|
+
});
|
|
63
|
+
this.app.singleton("http.serve", () => h3.serve);
|
|
64
|
+
}
|
|
71
65
|
};
|
|
72
66
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
var import_support = require("@h3ravel/support");
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/Request.ts
|
|
76
69
|
var Request = class {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
*/
|
|
125
|
-
async input(key, defaultValue) {
|
|
126
|
-
const data = await this.all();
|
|
127
|
-
return data[key] ?? defaultValue;
|
|
128
|
-
}
|
|
129
|
-
getEvent(key) {
|
|
130
|
-
return (0, import_support.safeDot)(this.event, key);
|
|
131
|
-
}
|
|
70
|
+
/**
|
|
71
|
+
* Gets route parameters.
|
|
72
|
+
* @returns An object containing route parameters.
|
|
73
|
+
*/
|
|
74
|
+
params;
|
|
75
|
+
/**
|
|
76
|
+
* Gets query parameters.
|
|
77
|
+
* @returns An object containing query parameters.
|
|
78
|
+
*/
|
|
79
|
+
query;
|
|
80
|
+
/**
|
|
81
|
+
* Gets the request headers.
|
|
82
|
+
* @returns An object containing request headers.
|
|
83
|
+
*/
|
|
84
|
+
headers;
|
|
85
|
+
/**
|
|
86
|
+
* The current H3 H3Event instance
|
|
87
|
+
*/
|
|
88
|
+
event;
|
|
89
|
+
constructor(event, app) {
|
|
90
|
+
this.app = app;
|
|
91
|
+
this.event = event;
|
|
92
|
+
this.query = (0, h3.getQuery)(this.event);
|
|
93
|
+
this.params = (0, h3.getRouterParams)(this.event);
|
|
94
|
+
this.headers = this.event.req.headers;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get all input data (query + body).
|
|
98
|
+
*/
|
|
99
|
+
async all() {
|
|
100
|
+
let data = {
|
|
101
|
+
...(0, h3.getRouterParams)(this.event),
|
|
102
|
+
...(0, h3.getQuery)(this.event)
|
|
103
|
+
};
|
|
104
|
+
if (this.event.req.method === "POST") data = Object.assign({}, data, Object.fromEntries((await this.event.req.formData()).entries()));
|
|
105
|
+
else if (this.event.req.method === "PUT") data = Object.fromEntries(Object.entries(await (0, h3.readBody)(this.event)));
|
|
106
|
+
return data;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get a single input field from query or body.
|
|
110
|
+
*/
|
|
111
|
+
async input(key, defaultValue) {
|
|
112
|
+
return (await this.all())[key] ?? defaultValue;
|
|
113
|
+
}
|
|
114
|
+
getEvent(key) {
|
|
115
|
+
return (0, __h3ravel_support.safeDot)(this.event, key);
|
|
116
|
+
}
|
|
132
117
|
};
|
|
133
118
|
|
|
134
|
-
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region src/Resources/JsonResource.ts
|
|
121
|
+
/**
|
|
122
|
+
* Class to render API resource
|
|
123
|
+
*/
|
|
135
124
|
var JsonResource = class {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
* @param code Status code
|
|
260
|
-
* @returns this
|
|
261
|
-
*/
|
|
262
|
-
status(code) {
|
|
263
|
-
this.response.status = code;
|
|
264
|
-
return this;
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* Private method to send the response
|
|
268
|
-
*/
|
|
269
|
-
#send() {
|
|
270
|
-
if (!this.responseSent) {
|
|
271
|
-
this.event.context.this.response.json(this.body);
|
|
272
|
-
this.responseSent = true;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* Check if send should be triggered automatically
|
|
277
|
-
*/
|
|
278
|
-
checkSend() {
|
|
279
|
-
if (this.shouldSend && !this.responseSent) {
|
|
280
|
-
this.#send();
|
|
281
|
-
}
|
|
282
|
-
}
|
|
125
|
+
/**
|
|
126
|
+
* The request instance
|
|
127
|
+
*/
|
|
128
|
+
request;
|
|
129
|
+
/**
|
|
130
|
+
* The response instance
|
|
131
|
+
*/
|
|
132
|
+
response;
|
|
133
|
+
/**
|
|
134
|
+
* The data to send to the client
|
|
135
|
+
*/
|
|
136
|
+
resource;
|
|
137
|
+
/**
|
|
138
|
+
* The final response data object
|
|
139
|
+
*/
|
|
140
|
+
body = { data: {} };
|
|
141
|
+
/**
|
|
142
|
+
* Flag to track if response should be sent automatically
|
|
143
|
+
*/
|
|
144
|
+
shouldSend = false;
|
|
145
|
+
/**
|
|
146
|
+
* Flag to track if response has been sent
|
|
147
|
+
*/
|
|
148
|
+
responseSent = false;
|
|
149
|
+
/**
|
|
150
|
+
* @param req The request instance
|
|
151
|
+
* @param res The response instance
|
|
152
|
+
* @param rsc The data to send to the client
|
|
153
|
+
*/
|
|
154
|
+
constructor(event, rsc) {
|
|
155
|
+
this.event = event;
|
|
156
|
+
this.request = event.req;
|
|
157
|
+
this.response = event.res;
|
|
158
|
+
this.resource = rsc;
|
|
159
|
+
for (const key of Object.keys(rsc)) if (!(key in this)) Object.defineProperty(this, key, {
|
|
160
|
+
enumerable: true,
|
|
161
|
+
configurable: true,
|
|
162
|
+
get: () => this.resource[key],
|
|
163
|
+
set: (value) => {
|
|
164
|
+
this.resource[key] = value;
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Return the data in the expected format
|
|
170
|
+
*
|
|
171
|
+
* @returns
|
|
172
|
+
*/
|
|
173
|
+
data() {
|
|
174
|
+
return this.resource;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Build the response object
|
|
178
|
+
* @returns this
|
|
179
|
+
*/
|
|
180
|
+
json() {
|
|
181
|
+
this.shouldSend = true;
|
|
182
|
+
this.response.status = 200;
|
|
183
|
+
const resource = this.data();
|
|
184
|
+
let data = Array.isArray(resource) ? [...resource] : { ...resource };
|
|
185
|
+
if (typeof data.data !== "undefined") data = data.data;
|
|
186
|
+
if (!Array.isArray(resource)) delete data.pagination;
|
|
187
|
+
this.body = { data };
|
|
188
|
+
if (!Array.isArray(resource) && resource.pagination) {
|
|
189
|
+
const meta = this.body.meta ?? {};
|
|
190
|
+
meta.pagination = resource.pagination;
|
|
191
|
+
this.body.meta = meta;
|
|
192
|
+
}
|
|
193
|
+
if (this.resource.pagination && !this.body.meta?.pagination) {
|
|
194
|
+
const meta = this.body.meta ?? {};
|
|
195
|
+
meta.pagination = this.resource.pagination;
|
|
196
|
+
this.body.meta = meta;
|
|
197
|
+
}
|
|
198
|
+
return this;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Add context data to the response object
|
|
202
|
+
* @param data Context data
|
|
203
|
+
* @returns this
|
|
204
|
+
*/
|
|
205
|
+
additional(data) {
|
|
206
|
+
this.shouldSend = true;
|
|
207
|
+
delete data.data;
|
|
208
|
+
delete data.pagination;
|
|
209
|
+
this.body = {
|
|
210
|
+
...this.body,
|
|
211
|
+
...data
|
|
212
|
+
};
|
|
213
|
+
return this;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Send the output to the client
|
|
217
|
+
* @returns this
|
|
218
|
+
*/
|
|
219
|
+
send() {
|
|
220
|
+
this.shouldSend = false;
|
|
221
|
+
if (!this.responseSent) this.#send();
|
|
222
|
+
return this;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Set the status code for this response
|
|
226
|
+
* @param code Status code
|
|
227
|
+
* @returns this
|
|
228
|
+
*/
|
|
229
|
+
status(code) {
|
|
230
|
+
this.response.status = code;
|
|
231
|
+
return this;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Private method to send the response
|
|
235
|
+
*/
|
|
236
|
+
#send() {
|
|
237
|
+
if (!this.responseSent) {
|
|
238
|
+
this.event.context.this.response.json(this.body);
|
|
239
|
+
this.responseSent = true;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Check if send should be triggered automatically
|
|
244
|
+
*/
|
|
245
|
+
checkSend() {
|
|
246
|
+
if (this.shouldSend && !this.responseSent) this.#send();
|
|
247
|
+
}
|
|
283
248
|
};
|
|
284
249
|
|
|
285
|
-
|
|
250
|
+
//#endregion
|
|
251
|
+
//#region src/Resources/ApiResource.ts
|
|
286
252
|
function ApiResource(instance) {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
return value;
|
|
305
|
-
}
|
|
306
|
-
});
|
|
253
|
+
return new Proxy(instance, { get(target, prop, receiver) {
|
|
254
|
+
const value = Reflect.get(target, prop, receiver);
|
|
255
|
+
if (typeof value === "function") {
|
|
256
|
+
if (prop === "json" || prop === "additional") return (...args) => {
|
|
257
|
+
const result = value.apply(target, args);
|
|
258
|
+
setImmediate(() => target["checkSend"]());
|
|
259
|
+
return result;
|
|
260
|
+
};
|
|
261
|
+
else if (prop === "send") return (...args) => {
|
|
262
|
+
target["shouldSend"] = false;
|
|
263
|
+
return value.apply(target, args);
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
return value;
|
|
267
|
+
} });
|
|
307
268
|
}
|
|
308
|
-
__name(ApiResource, "ApiResource");
|
|
309
269
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
var import_h33 = require("h3");
|
|
270
|
+
//#endregion
|
|
271
|
+
//#region src/Response.ts
|
|
313
272
|
var Response = class {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
}
|
|
378
|
-
getEvent(key) {
|
|
379
|
-
return (0, import_support2.safeDot)(this.event, key);
|
|
380
|
-
}
|
|
273
|
+
/**
|
|
274
|
+
* The current H3 H3Event instance
|
|
275
|
+
*/
|
|
276
|
+
event;
|
|
277
|
+
statusCode = 200;
|
|
278
|
+
headers = {};
|
|
279
|
+
constructor(event, app) {
|
|
280
|
+
this.app = app;
|
|
281
|
+
this.event = event;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Set HTTP status code.
|
|
285
|
+
*/
|
|
286
|
+
setStatusCode(code) {
|
|
287
|
+
this.statusCode = code;
|
|
288
|
+
this.event.res.status = code;
|
|
289
|
+
return this;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Set a header.
|
|
293
|
+
*/
|
|
294
|
+
setHeader(name, value) {
|
|
295
|
+
this.headers[name] = value;
|
|
296
|
+
return this;
|
|
297
|
+
}
|
|
298
|
+
html(content) {
|
|
299
|
+
this.applyHeaders();
|
|
300
|
+
return (0, h3.html)(this.event, content);
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Send a JSON response.
|
|
304
|
+
*/
|
|
305
|
+
json(data) {
|
|
306
|
+
this.setHeader("content-type", "application/json; charset=utf-8");
|
|
307
|
+
this.applyHeaders();
|
|
308
|
+
return data;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Send plain text.
|
|
312
|
+
*/
|
|
313
|
+
text(data) {
|
|
314
|
+
this.setHeader("content-type", "text/plain; charset=utf-8");
|
|
315
|
+
this.applyHeaders();
|
|
316
|
+
return data;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Redirect to another URL.
|
|
320
|
+
*/
|
|
321
|
+
redirect(url, status = 302) {
|
|
322
|
+
this.setStatusCode(status);
|
|
323
|
+
return (0, h3.redirect)(this.event, url, this.statusCode);
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Apply headers before sending response.
|
|
327
|
+
*/
|
|
328
|
+
applyHeaders() {
|
|
329
|
+
Object.entries(this.headers).forEach(([key, value]) => {
|
|
330
|
+
this.event.res.headers.set(key, value);
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
getEvent(key) {
|
|
334
|
+
return (0, __h3ravel_support.safeDot)(this.event, key);
|
|
335
|
+
}
|
|
381
336
|
};
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
Request,
|
|
391
|
-
Response
|
|
337
|
+
|
|
338
|
+
//#endregion
|
|
339
|
+
exports.ApiResource = ApiResource;
|
|
340
|
+
Object.defineProperty(exports, 'HttpContext', {
|
|
341
|
+
enumerable: true,
|
|
342
|
+
get: function () {
|
|
343
|
+
return __h3ravel_shared.HttpContext;
|
|
344
|
+
}
|
|
392
345
|
});
|
|
346
|
+
exports.HttpServiceProvider = HttpServiceProvider;
|
|
347
|
+
exports.JsonResource = JsonResource;
|
|
348
|
+
exports.LogRequests = LogRequests;
|
|
349
|
+
exports.Middleware = Middleware;
|
|
350
|
+
exports.Request = Request;
|
|
351
|
+
exports.Response = Response;
|
|
393
352
|
//# sourceMappingURL=index.cjs.map
|