fix(express): redirect 404s to index.html

This commit is contained in:
Sam Tolmay 2020-10-12 15:43:03 +02:00
parent 6fe4c70aa2
commit 218a59e9ce

View File

@ -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`));