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

[adapter-vercel] don't use top level await in Vercel Edge Functions #6360

Merged
merged 4 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/shiny-sloths-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@sveltejs/adapter-vercel': patch
'@sveltejs/adapter-netlify': patch
---

Don't use top-level-await, as it is not supported right now
5 changes: 3 additions & 2 deletions packages/adapter-netlify/src/edge.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { manifest, prerendered } from 'MANIFEST';
const server = new Server(manifest);
const prefix = `/${manifest.appDir}/`;

await server.init({
const initialized = server.init({
// @ts-ignore
env: Deno.env.toObject()
});
Expand All @@ -14,13 +14,14 @@ await server.init({
* @param { any } context
* @returns { Promise<Response> }
*/
export default function handler(request, context) {
export default async function handler(request, context) {
if (is_static_file(request)) {
// Static files can skip the handler
// TODO can we serve _app/immutable files with an immutable cache header?
return;
}

await initialized;
return server.respond(request, {
platform: { context },
getClientAddress() {
Expand Down
6 changes: 3 additions & 3 deletions packages/adapter-vercel/files/edge.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { Server } from 'SERVER';
import { manifest } from 'MANIFEST';

const server = new Server(manifest);

await server.init({
const initialized = server.init({
env: process.env
});

/**
* @param {Request} request
*/
export default (request) => {
export default async (request) => {
await initialized;
return server.respond(request, {
getClientAddress() {
return request.headers.get('x-forwarded-for');
Expand Down