Skip to content

Pluggable dev servers #278

@bennypowers

Description

@bennypowers

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions