1
- import type { Context } from 'https://edge.netlify.com '
2
- import { NextRequest , NextResponse } from 'https://esm.sh/next/ server'
3
- import { fromFileUrl } from 'https://deno.land/std/path/mod.ts'
1
+ import { NextRequest } from 'https://esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/request.js '
2
+ import { NextResponse } from 'https://esm.sh/v91/ next@12.2.5/deno/dist/ server/web/spec-extension/response.js '
3
+ import { fromFileUrl } from 'https://deno.land/std@0.151.0 /path/mod.ts'
4
4
import { buildResponse } from './utils.ts'
5
5
6
- export interface FetchEventResult {
7
- response : Response
8
- waitUntil : Promise < unknown >
9
- }
10
-
11
- interface I18NConfig {
12
- defaultLocale : string
13
- domains ?: DomainLocale [ ]
14
- localeDetection ?: false
15
- locales : string [ ]
16
- }
17
-
18
- interface DomainLocale {
19
- defaultLocale : string
20
- domain : string
21
- http ?: true
22
- locales ?: string [ ]
23
- }
24
- export interface NextRequestInit extends RequestInit {
25
- geo ?: {
26
- city ?: string
27
- country ?: string
28
- region ?: string
29
- }
30
- ip ?: string
31
- nextConfig ?: {
32
- basePath ?: string
33
- i18n ?: I18NConfig | null
34
- trailingSlash ?: boolean
35
- }
36
- }
37
-
38
- export interface RequestData {
39
- geo ?: {
40
- city ?: string
41
- country ?: string
42
- region ?: string
43
- latitude ?: string
44
- longitude ?: string
45
- }
46
- headers : Record < string , string >
47
- ip ?: string
48
- method : string
49
- nextConfig ?: {
50
- basePath ?: string
51
- i18n ?: Record < string , unknown >
52
- trailingSlash ?: boolean
53
- }
54
- page ?: {
55
- name ?: string
56
- params ?: { [ key : string ] : string }
57
- }
58
- url : string
59
- body ?: ReadableStream < Uint8Array >
60
- }
61
-
62
- export interface RequestContext {
63
- request : Request
64
- context : Context
65
- }
66
-
67
- declare global {
68
- // deno-lint-ignore no-var
69
- var NFRequestContextMap : Map < string , RequestContext >
70
- // deno-lint-ignore no-var
71
- var __dirname : string
72
- }
73
-
74
6
globalThis . NFRequestContextMap ||= new Map ( )
75
7
globalThis . __dirname = fromFileUrl ( new URL ( './' , import . meta. url ) ) . slice ( 0 , - 1 )
76
8
77
9
// Check if a file exists, given a relative path
78
- const exists = async ( relativePath : string ) => {
10
+ const exists = async ( relativePath ) => {
79
11
const path = fromFileUrl ( new URL ( relativePath , import . meta. url ) )
80
12
try {
81
13
await Deno . stat ( path )
@@ -88,7 +20,7 @@ const exists = async (relativePath: string) => {
88
20
}
89
21
}
90
22
91
- const handler = async ( req : Request , context : Context ) => {
23
+ const handler = async ( req , context ) => {
92
24
// Uncomment when CLI update lands
93
25
// if (!Deno.env.get('NETLIFY_DEV')) {
94
26
// // Only run in dev
@@ -111,7 +43,7 @@ const handler = async (req: Request, context: Context) => {
111
43
}
112
44
113
45
// This is the format expected by Next.js
114
- const geo : NextRequestInit [ 'geo' ] = {
46
+ const geo = {
115
47
country : context . geo . country ?. code ,
116
48
region : context . geo . subdivision ?. code ,
117
49
city : context . geo . city ,
@@ -125,15 +57,15 @@ const handler = async (req: Request, context: Context) => {
125
57
context,
126
58
} )
127
59
128
- const request : NextRequestInit = {
60
+ const request = {
129
61
headers : Object . fromEntries ( req . headers . entries ( ) ) ,
130
62
geo,
131
63
method : req . method ,
132
64
ip : context . ip ,
133
65
body : req . body || undefined ,
134
66
}
135
67
136
- const nextRequest : NextRequest = new NextRequest ( req , request )
68
+ const nextRequest = new NextRequest ( req , request )
137
69
138
70
try {
139
71
const response = await middleware ( nextRequest )
0 commit comments