File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -206,11 +206,22 @@ async function startServer() {
206206 await poops ( ) // Initial compilation before starting the server
207207 const app = connect ( )
208208
209- if ( config . serve . base && pathExists ( cwd , config . serve . base ) ) {
210- app . use ( serveStatic ( path . join ( cwd , config . serve . base ) ) )
211- } else {
212- app . use ( serveStatic ( cwd ) )
213- }
209+ const base = config . serve . base && pathExists ( cwd , config . serve . base )
210+ ? path . join ( cwd , config . serve . base )
211+ : cwd
212+
213+ app . use ( serveStatic ( base ) )
214+
215+ // Serve 404.html for unmatched routes
216+ const notFoundPage = path . join ( base , '404.html' )
217+ app . use ( ( req , res ) => {
218+ res . statusCode = 404
219+ if ( pathExists ( notFoundPage ) ) {
220+ fs . createReadStream ( notFoundPage ) . pipe ( res )
221+ } else {
222+ res . end ( 'Not Found' )
223+ }
224+ } )
214225
215226 let port = overridePort || config . serve . port || 4040
216227 if ( ! overridePort ) port = await getAvailablePort ( port , port + 10 )
You can’t perform that action at this time.
0 commit comments