11import type { NextApiRequest , NextApiResponse } from 'next' ;
2- import { NextResponse , type NextRequest } from 'next/server' ;
32import { checkSecurity , HANDLERS , methodNotAllowed , type Request , type Response } from './http' ;
43import bodyParser from 'body-parser' ;
54import type { TidewaveConfig } from './core' ;
@@ -12,7 +11,6 @@ const DEFAULT_CONFIG: TidewaveConfig = {
1211} ;
1312
1413type NextJsHandler = ( _req : NextApiRequest , _res : NextApiResponse ) => Promise < void > ;
15- type NextJsMiddleware = ( _req : NextRequest ) => Promise < NextResponse > ;
1614
1715type NextHandler = ( ) => ValueOrPromise < unknown > ;
1816
@@ -83,30 +81,3 @@ export async function tidewaveHandler(
8381 return res . status ( 404 ) . json ( { message : `Route not found: ${ req . method } ${ req . url } ` } ) ;
8482 } ;
8583}
86-
87- export function tidewaveMiddleware ( ) : NextJsMiddleware {
88- const env = process . env . NODE_ENV ;
89-
90- if ( ! ( env === 'development' ) ) {
91- throw Error (
92- `[Tidewave] tidewave is designed to only work on development environment, got: ${ env } ` ,
93- ) ;
94- }
95- return async function middleware (
96- req : NextRequest ,
97- next ?: NextJsMiddleware ,
98- ) : Promise < NextResponse > {
99- const { pathname } = req . nextUrl ;
100-
101- if ( ! isTidewaveRoute ( pathname ) && next ) return next ( req ) ;
102- if ( ! isTidewaveRoute ( pathname ) ) return NextResponse . next ( ) ;
103-
104- // since next.js v12, middleware doesn't
105- // accept relative URLs
106- return NextResponse . rewrite ( new URL ( `/api${ pathname } ` , req . url ) ) ;
107- } ;
108- }
109-
110- export function isTidewaveRoute ( pathname : string ) : boolean {
111- return pathname . startsWith ( '/tidewave' ) ;
112- }
0 commit comments