From 218a59e9ce36c7f21f4c8f6021610aeaca306bd7 Mon Sep 17 00:00:00 2001 From: Sam Tolmay Date: Mon, 12 Oct 2020 15:43:03 +0200 Subject: [PATCH] fix(express): redirect 404s to index.html --- packages/express/server.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/express/server.js b/packages/express/server.js index 5a02b01e3..e51a93010 100644 --- a/packages/express/server.js +++ b/packages/express/server.js @@ -36,5 +36,14 @@ const server = new ApolloServer({ typeDefs, resolvers, context }); const app = express(); server.applyMiddleware({ app }); + +// Serve Webpack shell files from './shell/dist' app.use(express.static('shell/dist')); + +// Redirect all 404 to index.html with status 200 +// This should always be the last route +app.use((req, res) => { + res.sendFile(path.resolve(process.cwd(), 'shell/dist/index.html')); +}); + app.listen({ port: 3000 }, () => console.log(`🚀 Server ready at http://localhost:3000`));