Skip to content
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

Pluggable dev servers #278

Open
bennypowers opened this issue May 24, 2022 · 1 comment
Open

Pluggable dev servers #278

bennypowers opened this issue May 24, 2022 · 1 comment

Comments

@bennypowers
Copy link

bennypowers commented May 24, 2022

Over at RHDS we're using spandx to allow us to develop with our local sources against redhat.com 'in production'.

We do this by proxying certain requests to a local dev server (web-dev-server)

If spandx' browsersync integration was pluggable, could be make do with a single dev server instance, and thus a single command, without need for terminal multiplexers?

relevant code:

spandx/app/spandx.js

Lines 197 to 229 in 34c5a64

proxy: {
target: internalProxyOrigin,
proxyReq: [
function (proxyReq, req, res) {
// find and set a header to keep track of the spandx origin
const url = new URL("http://localhost/");
url.hostname = req.headers.host.split(":")[0];
url.port = conf.port;
url.protocol = conf.bs.https ? "https:" : "http:";
const origin = url.origin;
// set a header for spandx origin and env on both the request and response
const env = _.findKey(
conf.host,
(host) => host === url.hostname
);
[res, proxyReq].forEach((r) => {
r.setHeader("X-Spandx-Env", env || "default");
r.setHeader("X-Spandx-Origin", origin);
});
if (typeof env === "undefined") {
if (!config.silent) {
console.warn(
`WARN request received at ${origin} which is not in the spandx config`
);
}
}
},
],
},
rewriteRules: _.concat(conf.rewriteRules, conf.bs.rewriteRules),

Y THO

some practical issues that came up:

  • bs uses connect middleware, which is old and boring (that's both a pro and a con i suppose) whereas wds uses koa middleware (async-friendly)
  • running two dev servers in parallel is awkward, I'd rather not have to bust out the terminal multiplexer to run this
  • there's some duplication between the routing table and import maps that maybe using wds-only could solve
@mwcz
Copy link
Contributor

mwcz commented Sep 19, 2022

Sorry I didn't see this sooner. spandx is in full maintenance mode and I don't anticipate adding any new features myself. That said, if you want to give it a go, I'd be happy to review and merge this feature.

I typically prefer the terminal multiplexer approach, because it makes interpreting log output so much easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants