Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new rawBody type on SvelteKit req #123

Merged
merged 58 commits into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
45824ce
chore: update deps
jthegedus Aug 18, 2021
f88feb4
chore: update deps
jthegedus Aug 18, 2021
d82acfd
chore: update tooling
jthegedus Aug 19, 2021
1a66a97
fix: pass Express Req rawBody to SvelteKit
jthegedus Aug 19, 2021
a58fb67
chore: expect error on app.js import
jthegedus Aug 19, 2021
8fad087
docs: update compat table
jthegedus Aug 19, 2021
0d06fb0
Merge branch 'main' into fix/sync-kit-rawbody-changes
jthegedus Aug 19, 2021
c9c355e
docs: fix formatting
jthegedus Aug 19, 2021
b2058ce
fix: remove unused params field
jthegedus Aug 19, 2021
94a7684
fix: remove comments about SvelteKit types
jthegedus Aug 19, 2021
d901bdd
fix: headers with set-cookie
jthegedus Aug 20, 2021
bbb33fc
Merge branch 'fix/sync-kit-rawbody-changes' of https://github.com/jth…
jthegedus Aug 20, 2021
d7293c6
refactor: extract & document kit header conversion
jthegedus Aug 20, 2021
703386a
refactor: generic header string[] replacement
jthegedus Aug 20, 2021
a10ff28
refactor: extract conversion to own file
jthegedus Aug 20, 2021
5df48e1
test: migrate to uvu from ava
jthegedus Aug 20, 2021
36a2626
fix: cp firebase-to-svelte-kit file to build dir
jthegedus Aug 20, 2021
aa3e2a2
refactor: correctly name test file
jthegedus Aug 20, 2021
671573e
fix: handle empty rawBody (type error in firebase)
jthegedus Aug 20, 2021
f0f5c2a
chore: correctly name test file
jthegedus Aug 21, 2021
15f536b
chore: align filenames with other adapters
jthegedus Aug 21, 2021
56e33b6
chore: type init & render :tada:
jthegedus Aug 22, 2021
fa2e37c
fix: pass express rawBody to Kit rawBody directly
jthegedus Aug 22, 2021
86f32e1
docs: explain tests in contrib guide
jthegedus Aug 22, 2021
da2f6be
fix: update kit dep to 155 & use public types
jthegedus Aug 22, 2021
ca0173c
docs: explain how & when tests are run
jthegedus Aug 22, 2021
069d551
fix: use uint8array on empty express.rawbody
jthegedus Aug 22, 2021
fe32101
test: capture unit tests in own dir
jthegedus Aug 22, 2021
e98a445
test: move integ tests from examples to test dir
jthegedus Aug 22, 2021
a900bf7
test: update integration tests dirs
jthegedus Aug 22, 2021
539ed24
fix: formatting
jthegedus Aug 22, 2021
3a7a302
chore: comment why java is in deps list
jthegedus Aug 22, 2021
bc24642
test: e2e w firebase emulator & curl
jthegedus Aug 22, 2021
9e499ce
test: fix job step label
jthegedus Aug 22, 2021
b849f89
test: quote working dirs matrix
jthegedus Aug 22, 2021
c3b5266
test: fail fast on integration tests
jthegedus Aug 22, 2021
548992a
test: align nodejs version with tool-versions
jthegedus Aug 22, 2021
6436afe
test: list dirs for debugging
jthegedus Aug 22, 2021
89d71d3
docs: update version compat table. fmt w deno
jthegedus Aug 22, 2021
37d8332
ci: use cd instead of working-dir
jthegedus Aug 22, 2021
e092988
test: fix e2e adapter install & enable verbose build
jthegedus Aug 22, 2021
ebcc288
chore: run func framework min version to 1.9
jthegedus Aug 22, 2021
1f6b6e7
test: e2e set fb emulator func support
jthegedus Aug 23, 2021
9e86fc3
test: integration tests using kit todo app temp
jthegedus Aug 23, 2021
210d614
ci: exec integration tests
jthegedus Aug 23, 2021
af6cfcf
test: integration matrix of params
jthegedus Aug 23, 2021
9e0270a
ci: fix matrix prefix
jthegedus Aug 23, 2021
c92d1d2
test: fix integration script ref of old dir
jthegedus Aug 23, 2021
d106a46
test: name integration test job
jthegedus Aug 23, 2021
1a4c666
test: use pnpm in integration tests
jthegedus Aug 23, 2021
7cc06b3
fix: cp tool-versions to generated test dir tmp/
jthegedus Aug 23, 2021
cb74526
chore: ts-expect-error shims import
jthegedus Aug 23, 2021
12f591a
test: install adapter deps in CI
jthegedus Aug 23, 2021
ca682ab
test: end-to-end test in CI
jthegedus Aug 23, 2021
37ed5ac
test: fix missing indicator from e2e test script
jthegedus Aug 23, 2021
8781973
test: rm use of windows & macos for integ & e2e
jthegedus Aug 23, 2021
f6eed9d
chore: rename ci jobs
jthegedus Aug 23, 2021
db53085
fix: cp tool-versions to test dir
jthegedus Aug 23, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
firebase 9.10.2
nodejs 14.17.0
pnpm 6.3.0
firebase 9.16.5
nodejs 14.17.5
pnpm 6.13.0
java openjdk-14.0.2
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ SvelteKit is still in Beta and the Adapter API is in flux, this can result in th

| Adapter Version | SvelteKit Version |
| --------------- | ----------------- |
| WIP | `1.0.0-next.152` |
| `0.11.x` | `1.0.0-next.152` |
| `0.10.x` | `1.0.0-next.132` |
| `0.9.1` | `1.0.0-next.122` |
| `0.9.0` | `1.0.0-next.120` |
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@
"node": "^14.13.1 || >= 16"
},
"dependencies": {
"esbuild": "^0.11.23",
"esbuild": "^0.12.20",
"kleur": "^4.1.4"
},
"peerDependencies": {
"@sveltejs/kit": "^1.0.0-next.132"
"@sveltejs/kit": "^1.0.0-next.152"
},
"devDependencies": {
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@sveltejs/kit": "1.0.0-next.132",
"@sveltejs/kit": "^1.0.0-next.152",
"@types/express": "^4.17.12",
"@types/node": "^14.14.35",
"ava": "^3.15.0",
Expand Down
83 changes: 40 additions & 43 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 31 additions & 25 deletions src/files/handler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// TODO: hardcoding the relative location makes this brittle
// @ts-expect-error
import {init, render} from '../output/server/app.js';

init();
Expand All @@ -7,40 +8,45 @@ init();
* Firebase Cloud Function handler for SvelteKit
*
* This function converts the Firebase Cloud Function (Express.js) Request object
* into a format consumable to the SvelteKit render() function, which is of type
* SvelteKit `import('types/hooks').StrictBody | null`
* into a format consumable to the SvelteKit render() function
*
* Relevant documentation - https://firebase.google.com/docs/functions/http-events#read_values_from_the_request
*
* @param {import('firebase-functions').https.Request} request
* @param {import('express').Response} response
* @returns {Promise<void>}
*/
const svelteKit = async ({body, headers, method, rawBody, url}, response) => {
const host = `${headers['x-forwarded-proto']}://${headers.host}`;
const {pathname, searchParams: searchParameters = ''} = new URL(url || '', host);
async function svelteKit(request, response) {
const rendered = await render(toSvelteKitRequest(request));

const finalRawBody =
headers['content-type'] === undefined ?
rawBody :
(headers['content-type'] === 'application/octet-stream' ?
body :
new TextDecoder(headers['content-encoding'] || 'utf-8').decode(rawBody));
return rendered ?
response.writeHead(rendered.status, rendered.headers).end(rendered.body) :
response.writeHead(404, 'Not Found').end();
}

const rendered = await render({
method,
headers,
path: pathname,
query: searchParameters,
rawBody: finalRawBody
});

if (rendered) {
const {status, headers, body} = rendered;
return response.writeHead(status, headers).end(body);
}
/**
* @param {import('firebase-functions').https.Request} request
* @return {import('@sveltejs/kit/types/internal').Incoming}
jthegedus marked this conversation as resolved.
Show resolved Hide resolved
*/
function toSvelteKitRequest(request) {
const host = `${request.headers['x-forwarded-proto']}://${request.headers.host}`;
const {pathname, searchParams: searchParameters} = new URL(
request.url || '',
host
);

return response.writeHead(404).end();
};
return {
// Incoming
method: request.method,
headers: request.headers,
rawBody: new Uint8Array(request.rawBody),
// Body: request.body, Why does SvelteKit not use body?
jthegedus marked this conversation as resolved.
Show resolved Hide resolved
// Location
host,
path: pathname,
params: request.params,
query: searchParameters
};
}

export default svelteKit;