-
-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dev Server Proxy #75
Comments
Thanks for the kind words! A lot of guys spend a lot of time making this great. 😄 This will be doable once #56 lands 👍 |
Thank you! ❤️ Merging #56 makes this possible: // preact.config.js
module.exports = function(config) {
config.devServer.proxy = [
{
// proxy requests matching a pattern:
path: '/api/**',
// where to proxy to:
target: 'http://api.example.com',
// optionally change Origin: and Host: headers to match target:
changeOrigin: true,
changeHost: true,
// optionally mutate request before proxying:
pathRewrite: function(path, request) {
// you can modify the outbound proxy request here:
delete req.headers.referer;
// common: remove first path segment: (/api/**)
return '/' + path.replace(/^\/[^\/]+\//, '');
},
// optionally mutate proxy response:
onProxyRes: function(proxyRes, req, res) {
// you can modify the response here:
proxyRes.headers.connection = 'keep-alive';
proxyRes.headers['cache-control'] = 'no-cache';
}
}
];
}; That said, I'd love to support parsing a // static-app.json
{
"redirects": [
{
"source": "/api/(.*)",
"destination": "http://api.example.com/$1",
"type": "proxy"
}
]
} Nice and clean, and it'd then also be available if your hosting provider supports the format. |
#56 landed closing this |
Hello,
First off, I just want to say thank you for creating and maintaining this amazing tool, it's an absolute delight to work with and makes it just so easy and quick to get a Preact PWA up and running.
This may be more of a feature request, but is there any way to specify a proxy for the development server to intercept/redirect calls in either the
package.json
or another configuration file?Thank you for any help you can provide.
The text was updated successfully, but these errors were encountered: