Skip to content

Instantly share code, notes, and snippets.

@tony19
Created February 25, 2018 17:06
Show Gist options
  • Save tony19/75b8b1e9c0136a9cebd78f0067d23a0a to your computer and use it in GitHub Desktop.
Save tony19/75b8b1e9c0136a9cebd78f0067d23a0a to your computer and use it in GitHub Desktop.
Running polyserve with URL-rewrite middleware
const {startServer} = require('polyserve');
const projectConfig = require('./polymer.json');
const serverOptions = {
compile: projectConfig.compile,
entryPoint: projectConfig.entryPoint,
port: 8080,
root: 'src',
};
(async () => {
await startServer(serverOptions, (app, options) => {
app.use((req, res, next) => {
if (req.url.startsWith('/foo')) {
req.url = req.url.replace(/^\/foo/, '');
}
return next();
});
return app;
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment