Unverified Commit 000be856 authored by Kiko Beats's avatar Kiko Beats Committed by GitHub

Edge Functions: expose `globalThis` (#30877)

This PR enables to access to `globalThis` in the context of a Edge function
parent 9a31a4fb
......@@ -85,6 +85,7 @@ export async function run(params: {
}
context.self = context
context.globalThis = context
cache = {
context,
......
/* global globalThis */
import { NextResponse } from 'next/server'
export function middleware(request) {
const url = request.nextUrl
if (url.pathname.endsWith('/globalthis')) {
return new NextResponse(JSON.stringify(Object.keys(globalThis)), {
headers: {
'content-type': 'application/json; charset=utf-8',
},
})
}
return new Response(null, {
headers: {
'req-url-basepath': request.nextUrl.basePath,
......
......@@ -344,6 +344,12 @@ function responseTests(locale = '') {
}
function interfaceTests(locale = '') {
it(`${locale} \`globalThis\` is accesible`, async () => {
const res = await fetchViaHTTP(context.appPort, '/interface/globalthis')
const globals = await res.json()
expect(globals.length > 0).toBe(true)
})
it(`${locale} should validate request url parameters from a static route`, async () => {
const res = await fetchViaHTTP(
context.appPort,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment