Skip to content

Commit

Permalink
feat(qwik-city): adapt to v1.2.0 API and refine dependencies (#127)
Browse files Browse the repository at this point in the history
* fix(qwik-city): unpin hono version for usability

* feat(qwik-city): set min target version to v1.2.0+

* refactor(qwik-city): update from original middleware

* chore: add changeset
  • Loading branch information
shuymn authored Aug 22, 2023
1 parent 1246289 commit bbe197a
Show file tree
Hide file tree
Showing 4 changed files with 395 additions and 35 deletions.
5 changes: 5 additions & 0 deletions .changeset/thirty-geese-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hono/qwik-city': patch
---

feat(qwik-city): adapt to qwik-city changes in v1.2.0
12 changes: 6 additions & 6 deletions packages/qwik-city/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
},
"homepage": "https://github.com/honojs/middleware",
"peerDependencies": {
"@builder.io/qwik": "^1.0.0",
"@builder.io/qwik-city": "^1.0.0",
"hono": "3.1.5"
"@builder.io/qwik": "^1.2.0",
"@builder.io/qwik-city": "^1.2.0",
"hono": "^3.1.5"
},
"devDependencies": {
"@builder.io/qwik": "^1.0.0",
"@builder.io/qwik-city": "^1.0.0",
"hono": "3.1.5"
"@builder.io/qwik": "^1.2.0",
"@builder.io/qwik-city": "^1.2.0",
"hono": "^3.1.5"
},
"engines": {
"node": ">=18"
Expand Down
25 changes: 17 additions & 8 deletions packages/qwik-city/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { _deserializeData, _serializeData, _verifySerializable } from '@builder.io/qwik'
import { setServerPlatform } from '@builder.io/qwik/server'
import type {
ServerRenderOptions,
ServerRequestEvent,
Expand All @@ -12,6 +13,16 @@ import {
import type { MiddlewareHandler } from 'hono'

export const qwikMiddleware = (opts: ServerRenderOptions): MiddlewareHandler => {
// eslint-disable-next-line @typescript-eslint/no-extra-semi
;(globalThis as any).TextEncoderStream = TextEncoderStream
const qwikSerializer = {
_deserializeData,
_serializeData,
_verifySerializable,
}
if (opts.manifest) {
setServerPlatform(opts.manifest)
}
return async (c, next) => {
const url = new URL(c.req.url)
const serverRequestEv: ServerRequestEvent<Response> = {
Expand All @@ -28,16 +39,17 @@ export const qwikMiddleware = (opts: ServerRenderOptions): MiddlewareHandler =>
resolve(response)
return writable
},
getClientConn: () => ({}),
platform: {},
env: c.env,
}
const qwikSerializer = {
_deserializeData,
_serializeData,
_verifySerializable,
}
const handledResponse = await requestHandler(serverRequestEv, opts, qwikSerializer)
if (handledResponse) {
handledResponse.completion.then((v) => {
if (v) {
console.error(v)
}
})
const response = await handledResponse.response
if (response) {
return response
Expand Down Expand Up @@ -81,6 +93,3 @@ class TextEncoderStream {
}
}
}

// eslint-disable-next-line @typescript-eslint/no-extra-semi
;(globalThis as any).TextEncoderStream = TextEncoderStream
Loading

0 comments on commit bbe197a

Please sign in to comment.