-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support setting http response status in functions
- Loading branch information
1 parent
481f2a8
commit 0283907
Showing
18 changed files
with
151 additions
and
39 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
10 changes: 10 additions & 0 deletions
10
integration/testdata/functions_http/functions/withHeaders.ts
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,10 @@ | ||
import { WithHeaders, permissions } from "@teamkeel/sdk"; | ||
|
||
export default WithHeaders(async (ctx, inputs) => { | ||
permissions.allow(); | ||
|
||
const value = ctx.headers.get("X-MyRequestHeader"); | ||
ctx.response.headers.set("X-MyResponseHeader", value || ""); | ||
|
||
return {}; | ||
}); |
7 changes: 7 additions & 0 deletions
7
integration/testdata/functions_http/functions/withQueryParams.ts
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,7 @@ | ||
import { WithQueryParams, permissions } from "@teamkeel/sdk"; | ||
|
||
export default WithQueryParams(async (ctx, inputs) => { | ||
permissions.allow(); | ||
|
||
return inputs; | ||
}); |
10 changes: 10 additions & 0 deletions
10
integration/testdata/functions_http/functions/withStatus.ts
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,10 @@ | ||
import { WithStatus, permissions } from "@teamkeel/sdk"; | ||
export default WithStatus(async (ctx, inputs) => { | ||
permissions.allow(); | ||
|
||
const { response } = ctx; | ||
response.headers.set("Location", "https://some.url"); | ||
response.status = 301; | ||
|
||
return null; | ||
}); |
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,7 @@ | ||
model TestModel { | ||
actions { | ||
read withQueryParams(Any) returns (Any) | ||
read withHeaders(Any) returns (Any) | ||
read withStatus(Any) returns (Any) | ||
} | ||
} |
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,50 @@ | ||
import { test, expect } from "vitest"; | ||
|
||
test("headers", async () => { | ||
const response = await fetch( | ||
process.env.KEEL_TESTING_ACTIONS_API_URL + "/withHeaders", | ||
{ | ||
body: "{}", | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"X-MyRequestHeader": "my-header-value", | ||
}, | ||
} | ||
); | ||
|
||
expect(response.status).toEqual(200); | ||
expect(response.headers.get("X-MyResponseHeader")).toEqual("my-header-value"); | ||
}); | ||
|
||
test("status", async () => { | ||
const response = await fetch( | ||
process.env.KEEL_TESTING_ACTIONS_API_URL + "/withStatus", | ||
{ | ||
body: "{}", | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
redirect: "manual", | ||
} | ||
); | ||
|
||
expect(response.status).toEqual(301); | ||
expect(response.headers.get("Location")).toEqual("https://some.url"); | ||
}); | ||
|
||
test("query params", async () => { | ||
const response = await fetch( | ||
process.env.KEEL_TESTING_ACTIONS_API_URL + | ||
"/withQueryParams?a=1&b=foo&c=true" | ||
); | ||
|
||
const body = await response.json(); | ||
|
||
expect(body).toEqual({ | ||
a: "1", | ||
b: "foo", | ||
c: "true", | ||
}); | ||
}); |
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
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
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
Oops, something went wrong.