Skip to content

Commit

Permalink
[fix] don't use top level await in Edge Functions (#6360)
Browse files Browse the repository at this point in the history
Fixes #6345
  • Loading branch information
Schniz authored Aug 29, 2022
1 parent 05e8240 commit 331e0a8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
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

0 comments on commit 331e0a8

Please sign in to comment.