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

Update adapters to use new app.render API #3133

Merged
merged 47 commits into from
Dec 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
94b0939
replace request.origin/path/query with request.url
Rich-Harris Dec 29, 2021
f17bcbf
fix some stuff
Rich-Harris Dec 29, 2021
941b3b6
typo
Rich-Harris Dec 29, 2021
55fa638
lint
Rich-Harris Dec 29, 2021
92094b1
fix test
Rich-Harris Dec 29, 2021
5c15f7e
fix xss vuln
Rich-Harris Dec 29, 2021
2bc4cd5
fix test
Rich-Harris Dec 29, 2021
39f25b1
gah
Rich-Harris Dec 29, 2021
145aaae
fixes
Rich-Harris Dec 29, 2021
9f454bf
simplify
Rich-Harris Dec 29, 2021
0a6e6cf
use pathname+search as key
Rich-Harris Dec 29, 2021
4511c61
all tests passing
Rich-Harris Dec 29, 2021
bd496f3
lint
Rich-Harris Dec 29, 2021
c581a24
tidy up
Rich-Harris Dec 29, 2021
109108f
update types in docs
Rich-Harris Dec 29, 2021
c74cfe7
update docs
Rich-Harris Dec 29, 2021
c9a2794
more docs
Rich-Harris Dec 29, 2021
921e572
more docs
Rich-Harris Dec 29, 2021
a1ae42d
more docs
Rich-Harris Dec 29, 2021
0d70de6
i would be lost without conduitry
Rich-Harris Dec 29, 2021
28d5c1e
update template app
Rich-Harris Dec 29, 2021
b12931f
throw useful error when trying to access path/query/origin/page
Rich-Harris Dec 29, 2021
bc8c0ce
$params -> $route.params, only use getters in dev, remove the word "d…
Rich-Harris Dec 29, 2021
c83cad6
update docs
Rich-Harris Dec 29, 2021
f9e80fe
finish updating load input section
Rich-Harris Dec 29, 2021
efacc75
update
Rich-Harris Dec 29, 2021
310c10a
make this section less verbose
Rich-Harris Dec 29, 2021
3a104fa
move url into $route
Rich-Harris Dec 29, 2021
1ac14f2
update some docs
Rich-Harris Dec 29, 2021
3d6a30f
rename route store back to page
Rich-Harris Dec 29, 2021
0a53d92
throw errors on accessing $page.path etc
Rich-Harris Dec 29, 2021
761ab4c
fix types
Rich-Harris Dec 29, 2021
fc4caa1
fix some docs
Rich-Harris Dec 29, 2021
76376f4
fix migrating docs
Rich-Harris Dec 29, 2021
77030b3
decode path, strip prefix
Rich-Harris Dec 29, 2021
f0b6825
tidy up
Rich-Harris Dec 29, 2021
b1aa476
remove comment
Rich-Harris Dec 29, 2021
a12cfda
lint
Rich-Harris Dec 29, 2021
cd6c6c1
update adapters
Rich-Harris Dec 30, 2021
1f936b5
changeset
Rich-Harris Dec 30, 2021
863b602
error if adapter provides wrong input
Rich-Harris Dec 30, 2021
b675e1c
changeset
Rich-Harris Dec 30, 2021
aa2cc22
Merge branch 'master' into gh-3078
Rich-Harris Dec 30, 2021
3aa32c1
Update documentation/docs/05-modules.md
Rich-Harris Dec 30, 2021
18382d7
Update documentation/migrating/04-pages.md
Rich-Harris Dec 30, 2021
ea413b3
remove unused code
Rich-Harris Dec 30, 2021
ad20046
Merge branch 'gh-3078' of github.com:sveltejs/kit into gh-3078
Rich-Harris Dec 30, 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
9 changes: 9 additions & 0 deletions .changeset/honest-beers-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@sveltejs/adapter-cloudflare': patch
'@sveltejs/adapter-cloudflare-workers': patch
'@sveltejs/adapter-netlify': patch
'@sveltejs/adapter-node': patch
'@sveltejs/adapter-vercel': patch
---

Update adapters to provide app.render with a url
5 changes: 5 additions & 0 deletions .changeset/rude-balloons-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Error if adapter provides wrong input to app.render
5 changes: 5 additions & 0 deletions .changeset/shy-oranges-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Replace [request|page].[origin|path|query] with url object
4 changes: 1 addition & 3 deletions packages/adapter-cloudflare-workers/files/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ async function handle(event) {

// fall back to an app route
const request = event.request;
const request_url = new URL(request.url);

try {
const rendered = await app.render({
path: request_url.pathname,
query: request_url.searchParams,
url: request.url,
rawBody: await read(request),
headers: Object.fromEntries(request.headers),
method: request.method
Expand Down
3 changes: 1 addition & 2 deletions packages/adapter-cloudflare/files/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ export default {
// dynamically-generated pages
try {
const rendered = await app.render({
path: url.pathname,
query: url.searchParams,
url,
rawBody: new Uint8Array(await req.arrayBuffer()),
headers: Object.fromEntries(req.headers),
method: req.method
Expand Down
7 changes: 2 additions & 5 deletions packages/adapter-netlify/src/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@ export function init(manifest) {
const app = new App(manifest);

return async (event) => {
const { path, httpMethod, headers, rawQuery, body, isBase64Encoded } = event;

const query = new URLSearchParams(rawQuery);
const { httpMethod, headers, rawUrl, body, isBase64Encoded } = event;

const encoding = isBase64Encoded ? 'base64' : headers['content-encoding'] || 'utf-8';
const rawBody = typeof body === 'string' ? Buffer.from(body, encoding) : body;

const rendered = await app.render({
url: rawUrl,
method: httpMethod,
headers,
path,
query,
rawBody
});

Expand Down
11 changes: 1 addition & 10 deletions packages/adapter-node/src/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@ const serve_prerendered = sirv(path.join(__dirname, '/prerendered'), {

/** @type {import('polka').Middleware} */
const ssr = async (req, res) => {
let parsed;
try {
parsed = new URL(req.url || '', 'http://localhost');
} catch (e) {
res.statusCode = 400;
return res.end('Invalid URL');
}

let body;

try {
Expand All @@ -57,10 +49,9 @@ const ssr = async (req, res) => {
}

const rendered = await app.render({
url: req.url,
method: req.method,
headers: req.headers, // TODO: what about repeated headers, i.e. string[]
path: parsed.pathname,
query: parsed.searchParams,
rawBody: body
});

Expand Down
5 changes: 1 addition & 4 deletions packages/adapter-vercel/files/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ __fetch_polyfill();
const app = new App(manifest);

export default async (req, res) => {
const { pathname, searchParams } = new URL(req.url || '', 'http://localhost');

let body;

try {
Expand All @@ -20,10 +18,9 @@ export default async (req, res) => {
}

const rendered = await app.render({
url: req.url,
method: req.method,
headers: req.headers,
path: pathname,
query: searchParams,
rawBody: body
});

Expand Down
5 changes: 5 additions & 0 deletions packages/kit/src/core/build/build_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ export class App {
render(request, {
prerender
} = {}) {
// TODO remove this for 1.0
if (Object.keys(request).sort().join() !== 'headers,method,rawBody,url') {
throw new Error('Adapters should call app.render({ url, method, headers, rawBody })');
}

const host = ${
config.kit.host
? s(config.kit.host)
Expand Down