-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added h3 server handler to @ingest/h3. (#310)
## Summary Added h3 server handler to @ingest/h3. h3 is the unjs project which is the foundation for the Nuxt 3 server `eventHandlers`. This MR provides backwards compatibility between Nuxt and h3, and can also be used within a nitro server setup too. Includes bumping h3 to the latest version (v1.8.1). ## Checklist - [ ] Added a [docs PR](https://github.com/inngest/website) that references this PR - [X] Added unit/integration tests - [X] Added changesets if applicable --------- Co-authored-by: Jack Williams <1736957+jpwilliams@users.noreply.github.com>
- inngest@3.28.0
- inngest@3.27.5
- inngest@3.27.4
- inngest@3.27.3
- inngest@3.27.2
- inngest@3.27.1
- inngest@3.27.0
- inngest@3.26.3
- inngest@3.26.2
- inngest@3.26.1
- inngest@3.26.0
- inngest@3.25.1
- inngest@3.23.1
- inngest@3.23.0
- inngest@3.22.13
- inngest@3.22.12
- inngest@3.22.11
- inngest@3.22.10
- inngest@3.22.9
- inngest@3.22.8
- inngest@3.22.7
- inngest@3.22.6
- inngest@3.22.5
- inngest@3.22.4
- inngest@3.22.3
- inngest@3.22.2
- inngest@3.22.1
- inngest@3.22.0
- inngest@3.21.2
- inngest@3.21.1
- inngest@3.21.0
- inngest@3.20.0
- inngest@3.19.22
- inngest@3.19.21
- inngest@3.19.20
- inngest@3.19.19
- inngest@3.19.18
- inngest@3.19.17
- inngest@3.19.16
- inngest@3.19.15
- inngest@3.19.14
- inngest@3.19.13
- inngest@3.19.12
- inngest@3.19.11
- inngest@3.19.10
- inngest@3.19.9
- inngest@3.19.8
- inngest@3.19.7
- inngest@3.19.4
- inngest@3.19.3
- inngest@3.19.2
- inngest@3.19.1
- inngest@3.19.0
- inngest@3.18.1
- inngest@3.18.0
- inngest@3.17.0
- inngest@3.16.2
- inngest@3.16.1
- inngest@3.16.0
- inngest@3.15.5
- inngest@3.15.4
- inngest@3.15.3
- inngest@3.15.2
- inngest@3.15.1
- inngest@3.15.0
- inngest@3.14.2
- inngest@3.14.1
- inngest@3.14.0
- inngest@3.13.0
- inngest@3.12.0
- inngest@3.11.0
- inngest@3.10.0
- inngest@3.9.0
- inngest@3.8.0
- inngest@3.7.4
- inngest@3.7.3
- inngest@3.7.2
- inngest@3.7.1
- inngest@3.7.0
- inngest@3.6.2
- inngest@3.6.1
- inngest@3.6.0
- inngest@3.5.0
- inngest@3.4.4
- inngest@3.4.3
- inngest@3.4.2
- inngest@3.4.1
- inngest@3.4.0
- inngest@3.3.0
- inngest@3.2.1
- inngest@3.1.1
- inngest@3.1.0
- inngest@3.0.2
- inngest@3.0.1
- inngest@3.0.0
- inngest@2.7.2
- inngest@2.7.1
- inngest@2.7.0
- @inngest/test@0.1.5
- @inngest/test@0.1.4
- @inngest/test@0.1.3
- @inngest/test@0.1.2
- @inngest/test@0.1.1
- @inngest/test@0.1.0
- @inngest/test@0.0.0
- @inngest/middleware-validation@0.0.1
- @inngest/middleware-sentry@0.1.1
- @inngest/middleware-sentry@0.1.0
- @inngest/middleware-encryption@1.0.0
- @inngest/middleware-encryption@0.1.7
- @inngest/middleware-encryption@0.1.6
- @inngest/middleware-encryption@0.1.5
- @inngest/middleware-encryption@0.1.3
- @inngest/middleware-encryption@0.1.2
- @inngest/middleware-encryption@0.1.1
- @inngest/middleware-encryption@0.1.0
- @inngest/eslint-plugin@0.0.7
- @inngest/eslint-plugin@0.0.6
- @inngest/eslint-plugin@0.0.5
- @inngest/eslint-plugin@0.0.4
- @inngest/eslint-plugin@0.0.2
- @inngest/eslint-plugin@0.0.1
1 parent
32c34b3
commit 696c411
Showing
9 changed files
with
188 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"inngest": minor | ||
--- | ||
|
||
Added h3 framework server handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import * as h3Handler from "@local/h3"; | ||
import { createEvent } from "h3"; | ||
import { testFramework } from "./test/helpers"; | ||
|
||
testFramework("h3", h3Handler, { | ||
transformReq(req, res) { | ||
return [createEvent(req, res)]; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { | ||
getHeader, | ||
getQuery, | ||
readBody, | ||
send, | ||
setHeaders, | ||
type H3Event, | ||
} from "h3"; | ||
import { | ||
InngestCommHandler, | ||
type ServeHandler, | ||
} from "./components/InngestCommHandler"; | ||
import { headerKeys, queryKeys } from "./helpers/consts"; | ||
import { processEnv } from "./helpers/env"; | ||
import { type SupportedFrameworkName } from "./types"; | ||
|
||
export const name: SupportedFrameworkName = "h3"; | ||
|
||
/** | ||
* In h3, serve and register any declared functions with Inngest, making | ||
* them available to be triggered by events. | ||
* | ||
* @public | ||
*/ | ||
export const serve: ServeHandler = (nameOrInngest, fns, opts) => { | ||
const handler = new InngestCommHandler( | ||
name, | ||
nameOrInngest, | ||
fns, | ||
opts, | ||
(event: H3Event) => { | ||
const host = String(getHeader(event, "host")); | ||
const protocol = | ||
processEnv("NODE_ENV") === "development" ? "http" : "https"; | ||
const url = new URL(String(event.path), `${protocol}://${host}`); | ||
const method = event.method; | ||
const query = getQuery(event); | ||
|
||
return { | ||
url, | ||
run: async () => { | ||
if (method === "POST") { | ||
return { | ||
fnId: query[queryKeys.FnId]?.toString() ?? "", | ||
stepId: query[queryKeys.StepId]?.toString() ?? "", | ||
signature: getHeader(event, headerKeys.Signature), | ||
data: await readBody(event), | ||
}; | ||
} | ||
}, | ||
register: () => { | ||
if (method === "PUT") { | ||
return { | ||
deployId: query[queryKeys.DeployId]?.toString(), | ||
}; | ||
} | ||
}, | ||
view: () => { | ||
if (method === "GET") { | ||
return { | ||
isIntrospection: query && queryKeys.Introspect in query, | ||
}; | ||
} | ||
}, | ||
}; | ||
}, | ||
(actionRes, event: H3Event) => { | ||
const { res } = event.node; | ||
res.statusCode = actionRes.status; | ||
setHeaders(event, actionRes.headers); | ||
return send(event, actionRes.body); | ||
} | ||
); | ||
|
||
return handler.createHandler(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.