File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import express from "express" ;
22import fetch from "node-fetch" ;
3+ import fs from "fs" ;
4+ import path from "path" ;
35
46const app = express ( ) ;
57const port = process . env . PORT || 8000 ;
68
79console . log ( "ENV PORT:" , process . env . PORT ) ;
810
11+ // Middleware to rewrite URLs - add .html if needed (like GitHub Pages)
12+ app . use ( ( req , res , next ) => {
13+ // Skip if it's the proxy endpoint, health check, or already has an extension
14+ if ( req . path === '/proxy' || req . path === '/health' || req . path . includes ( '.' ) ) {
15+ return next ( ) ;
16+ }
17+
18+ // If path doesn't end with .html, try to serve the .html version
19+ if ( ! req . path . endsWith ( '.html' ) && ! req . path . endsWith ( '/' ) ) {
20+ const htmlPath = req . path + '.html' ;
21+
22+ if ( fs . existsSync ( path . join ( '.' , htmlPath ) ) ) {
23+ req . url = htmlPath ;
24+ }
25+ }
26+
27+ next ( ) ;
28+ } ) ;
29+
930// Serve static files (all your gh-pages HTML, CSS, JS, assets at repo root)
1031app . use ( express . static ( '.' ) ) ;
1132
You can’t perform that action at this time.
0 commit comments