11import 'SHIMS' ;
22import { env } from 'ENV' ;
3- import { manifest } from 'MANIFEST' ;
3+ import { manifest , prerendered , base } from 'MANIFEST' ;
44import { Server } from 'SERVER' ;
55// 🔥 Use our robust converters instead of basic event parsing
66import {
77 convertLambdaEventToWebRequest ,
88 convertWebResponseToLambdaEvent ,
99} from '@foladayo/lambda-adapter-kit' ;
1010import { getRequest } from '@sveltejs/kit/node' ;
11- import { readFileSync } from 'node:fs' ;
12- import { fileURLToPath } from 'node:url' ;
13- import { dirname , join , extname } from 'node:path' ;
1411
1512/* global ENV_PREFIX */
1613
@@ -19,9 +16,6 @@ const server = new Server(manifest);
1916const body_size_limit = Number . parseInt ( env ( 'BODY_SIZE_LIMIT' , 'BODY_SIZE_LIMIT' ) ) ;
2017const binaryMediaTypes = BINARY_MEDIA_TYPES ;
2118
22- // Get the directory of this handler file
23- const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
24-
2519await server . init ( {
2620 env : process . env ,
2721} ) ;
@@ -90,50 +84,24 @@ function isALBEvent(event) {
9084}
9185
9286/**
93- * Serve static files from the bundled client directory
94- * @param {string } path - The requested path
95- * @returns {Promise<Response|null> } - Response for static file or null if not found
87+ * Check if request is for static assets
88+ * @param {string } pathname
89+ * @returns {boolean }
9690 */
97- async function tryServeStaticFile ( path ) {
98- // Handle client assets (JS, CSS, etc.)
99- if ( path . startsWith ( '/_app/' ) || path . startsWith ( '/favicon.ico' ) ) {
100- try {
101- const filePath = join ( __dirname , 'client' , path ) ;
102- const content = readFileSync ( filePath ) ;
103-
104- // Determine content type
105- const ext = extname ( path ) . toLowerCase ( ) ;
106- const contentType = {
107- '.js' : 'application/javascript' ,
108- '.css' : 'text/css' ,
109- '.ico' : 'image/x-icon' ,
110- '.png' : 'image/png' ,
111- '.jpg' : 'image/jpeg' ,
112- '.jpeg' : 'image/jpeg' ,
113- '.gif' : 'image/gif' ,
114- '.svg' : 'image/svg+xml' ,
115- '.woff' : 'font/woff' ,
116- '.woff2' : 'font/woff2' ,
117- '.ttf' : 'font/ttf' ,
118- '.eot' : 'application/vnd.ms-fontobject'
119- } [ ext ] || 'application/octet-stream' ;
120-
121- return new Response ( content , {
122- status : 200 ,
123- headers : {
124- 'Content-Type' : contentType ,
125- 'Cache-Control' : path . includes ( '/immutable/' )
126- ? 'public, max-age=31536000, immutable'
127- : 'public, max-age=3600'
128- }
129- } ) ;
130- } catch ( error ) {
131- // File not found or error reading
132- return null ;
133- }
134- }
135-
136- return null ;
91+ function isStaticAsset ( pathname ) {
92+ return pathname . startsWith ( `${ base } /_app/` ) ||
93+ pathname . startsWith ( `${ base } /favicon.` ) ||
94+ pathname . endsWith ( '.css' ) ||
95+ pathname . endsWith ( '.js' ) ||
96+ pathname . endsWith ( '.woff' ) ||
97+ pathname . endsWith ( '.woff2' ) ||
98+ pathname . endsWith ( '.png' ) ||
99+ pathname . endsWith ( '.jpg' ) ||
100+ pathname . endsWith ( '.jpeg' ) ||
101+ pathname . endsWith ( '.gif' ) ||
102+ pathname . endsWith ( '.svg' ) ||
103+ pathname . endsWith ( '.webp' ) ||
104+ pathname . endsWith ( '.ico' ) ;
137105}
138106
139107/**
@@ -146,14 +114,18 @@ export const handler = async (event, context) => {
146114 try {
147115 // 🔥 Use our superior event conversion (handles all Lambda event types)
148116 const webRequest = convertLambdaEventToWebRequest ( event ) ;
117+ const pathname = new URL ( webRequest . url ) . pathname ;
149118
150- // Try to serve static files first
151- const staticFileResponse = await tryServeStaticFile ( new URL ( webRequest . url ) . pathname ) ;
152- if ( staticFileResponse ) {
153- return await convertWebResponseToLambdaEvent ( staticFileResponse , {
154- binaryMediaTypes,
155- multiValueHeaders : isALBEvent ( event ) ,
156- } ) ;
119+ // Check for prerendered routes
120+ if ( prerendered . has ( pathname ) ) {
121+ // Let SvelteKit handle prerendered routes
122+ // Fall through to normal processing
123+ }
124+
125+ // Static assets - let SvelteKit handle them
126+ if ( isStaticAsset ( pathname ) ) {
127+ // Let SvelteKit handle static assets
128+ // Fall through to normal processing
157129 }
158130
159131 // Convert to Node.js request format for SvelteKit
0 commit comments