@kiyasov/platform-hono 1.3.8 → 1.3.10
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/cjs/src/adapters/hono-adapter.d.ts +6 -6
- package/dist/cjs/src/adapters/hono-adapter.js +61 -13
- package/dist/cjs/src/adapters/hono-adapter.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/adapters/hono-adapter.d.ts +6 -6
- package/dist/esm/src/adapters/hono-adapter.js +61 -13
- package/dist/esm/src/adapters/hono-adapter.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/adapters/hono-adapter.ts +79 -13
package/package.json
CHANGED
|
@@ -126,7 +126,7 @@ export class HonoAdapter extends AbstractHttpAdapter<
|
|
|
126
126
|
public async reply(ctx: Context, body: any, statusCode?: StatusCode) {
|
|
127
127
|
if (statusCode) ctx.status(statusCode);
|
|
128
128
|
|
|
129
|
-
const responseContentType = this.getHeader(ctx, "Content-Type");
|
|
129
|
+
const responseContentType = await this.getHeader(ctx, "Content-Type");
|
|
130
130
|
if (
|
|
131
131
|
!responseContentType?.startsWith("application/json") &&
|
|
132
132
|
body?.statusCode >= HttpStatus.BAD_REQUEST
|
|
@@ -139,8 +139,19 @@ export class HonoAdapter extends AbstractHttpAdapter<
|
|
|
139
139
|
ctx.set("body", body);
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
public status(
|
|
143
|
-
ctx
|
|
142
|
+
public async status(
|
|
143
|
+
ctx: Context | (() => Promise<Context>),
|
|
144
|
+
statusCode: StatusCode
|
|
145
|
+
) {
|
|
146
|
+
if (typeof ctx === "function") {
|
|
147
|
+
ctx = await ctx();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (ctx && typeof ctx.status === "function") {
|
|
151
|
+
ctx.status(statusCode);
|
|
152
|
+
} else {
|
|
153
|
+
throw new Error("Invalid context: status method not found.");
|
|
154
|
+
}
|
|
144
155
|
}
|
|
145
156
|
|
|
146
157
|
public async end() {
|
|
@@ -151,8 +162,20 @@ export class HonoAdapter extends AbstractHttpAdapter<
|
|
|
151
162
|
throw new Error("Method not implemented.");
|
|
152
163
|
}
|
|
153
164
|
|
|
154
|
-
public redirect(
|
|
155
|
-
ctx
|
|
165
|
+
public async redirect(
|
|
166
|
+
ctx: Context | (() => Promise<Context>),
|
|
167
|
+
statusCode: RedirectStatusCode,
|
|
168
|
+
url: string
|
|
169
|
+
) {
|
|
170
|
+
if (typeof ctx === "function") {
|
|
171
|
+
ctx = await ctx();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (ctx && typeof ctx.redirect === "function") {
|
|
175
|
+
ctx.redirect(url, statusCode);
|
|
176
|
+
} else {
|
|
177
|
+
throw new Error("Invalid context: redirect method not found.");
|
|
178
|
+
}
|
|
156
179
|
}
|
|
157
180
|
|
|
158
181
|
public setErrorHandler(handler: ErrorHandler) {
|
|
@@ -182,20 +205,63 @@ export class HonoAdapter extends AbstractHttpAdapter<
|
|
|
182
205
|
return true;
|
|
183
206
|
}
|
|
184
207
|
|
|
185
|
-
public getHeader?(
|
|
186
|
-
|
|
208
|
+
public async getHeader?(
|
|
209
|
+
ctx: Context | (() => Promise<Context>),
|
|
210
|
+
name: string
|
|
211
|
+
) {
|
|
212
|
+
if (typeof ctx === "function") {
|
|
213
|
+
ctx = await ctx();
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (ctx && typeof ctx.req.header === "function") {
|
|
217
|
+
return ctx.req.header(name);
|
|
218
|
+
} else {
|
|
219
|
+
throw new Error("Invalid context: get method not found on context.");
|
|
220
|
+
}
|
|
187
221
|
}
|
|
188
222
|
|
|
189
|
-
public setHeader(
|
|
190
|
-
ctx
|
|
223
|
+
public async setHeader(
|
|
224
|
+
ctx: Context | (() => Promise<Context>),
|
|
225
|
+
name: string,
|
|
226
|
+
value: string
|
|
227
|
+
) {
|
|
228
|
+
if (typeof ctx === "function") {
|
|
229
|
+
ctx = await ctx();
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (ctx && typeof ctx.header === "function") {
|
|
233
|
+
ctx.header(name, value);
|
|
234
|
+
} else {
|
|
235
|
+
throw new Error("Invalid context: set method not found on context.");
|
|
236
|
+
}
|
|
191
237
|
}
|
|
192
238
|
|
|
193
|
-
public appendHeader?(
|
|
194
|
-
ctx
|
|
239
|
+
public async appendHeader?(
|
|
240
|
+
ctx: Context | (() => Promise<Context>),
|
|
241
|
+
name: string,
|
|
242
|
+
value: string
|
|
243
|
+
) {
|
|
244
|
+
if (typeof ctx === "function") {
|
|
245
|
+
ctx = await ctx();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (ctx && typeof ctx.res.headers.append === "function") {
|
|
249
|
+
ctx.res.headers.append(name, value);
|
|
250
|
+
} else {
|
|
251
|
+
throw new Error("Invalid context: append method not found on context.");
|
|
252
|
+
}
|
|
195
253
|
}
|
|
196
254
|
|
|
197
|
-
public getRequestHostname(ctx: Context)
|
|
198
|
-
|
|
255
|
+
public async getRequestHostname(ctx: Context | (() => Promise<Context>)) {
|
|
256
|
+
if (typeof ctx === "function") {
|
|
257
|
+
ctx = await ctx();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (ctx && typeof ctx.req.header === "function") {
|
|
261
|
+
return ctx.req.header("host");
|
|
262
|
+
} else {
|
|
263
|
+
throw new Error("Invalid context: get method not found on context.");
|
|
264
|
+
}
|
|
199
265
|
}
|
|
200
266
|
|
|
201
267
|
public getRequestMethod(request: HonoRequest): string {
|