-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
Add ability to proxy local domain #9
Comments
https://browsersync.io/docs/options/#option-proxy this one, right? |
Indeed. I think having such an option opens up a lots of possibilities for a local dev server. A common use case for me would be when working with local installs of more traditional CMSes, etc. With a proxy and a watch dir(s) options, I could use eleventy-dev-server to watch my templates, assets directories, etc. and proxy my local domain. For reference, here is a sample Browsersync CLI line from my NPM scripts
|
Can you provide one (or more 😅) very specific example of how you use this? I just want to make sure I understand exactly what you’re looking for |
This is (mainly) related to uses cases for Browsersync outside of an Eleventy context, so maybe it is out of scope for this project. I work a lot with Craft CMS in headless mode or not. In those instances I run a LAMP stack locally that mirrors my production server as closely as possible. A custom I then run Browsersync in proxy mode through the CLI in NPM script so that I can then watch any files / directories I want with Browsersync and it will either inject changes (CSS/images) or make a full page refresh (when changing a Twig template) Sample NPM scripts for a hypothetical Craft build (sorry no public repo right now but I could give you access to a private one if that helps)
Not strictly related to Hope that's a bit clearer for you and that I didn't ramble too much 😅 |
@zachleat For example, we may want another server to interpret PHP while taking advantage of the dev server's features, and Browsersync can easily achieve this with a command like |
I can. I use Ghost for most of my websites, and I use a local install to develop themes. Ghost runs on browserSync.init({proxy: 'http://localhost:2368'}) It would be great to have this in eleventy-dev-server. I love how fast and lightweight it is compared to BrowserSync, but right now I can't use it for Ghost theme development. |
I would find this very helpful for our (@adobe/spectrum-css) documentation site which is migrating to 11ty. When in development mode, I'd like my developers to be able to live update the docs site and run the storybook server in parallel - with our built-in preview link in the navigation linking directly to the proxy instead of a static storybook build. |
Just chiming in, I know its undocumented, but would a workaround for now be to add a middleware to the 11ty dev server? I went spelunking through the Vite server and found this: and am semi-curious if it could work for proxying as well. |
…acks, related to #9
This is possible today using the eleventyConfig.setServerOptions({
onRequest: {
// proxy all paths (change this!)
"/*": async function(req) {
let response = await fetch(new URL(req.url.pathname, "https://www.zachleat.com/"));
return {
status: response.status,
headers: {
"content-type": response.headers.get("content-type"),
},
body: await response.bytes(),
};
}
}
}); Further, I just added a feature in the soon-to-be-released Dev Server 2.0.7 to support eleventyConfig.setServerOptions({
onRequest: {
// proxy all paths (change this!)
"/*": function(req) {
return fetch(new URL(req.url.pathname, "https://www.zachleat.com/"));
}
}
}); |
Just one more small note: |
In the spirit of using this outside of 11ty / Jamstack contexts, a Browsersync feature I am missing righ now (unless I am mistaken) is the ability to proxy a local domain.
The text was updated successfully, but these errors were encountered: