Skip to content

Instantly share code, notes, and snippets.

@ekaitz-zarraga
Last active December 4, 2017 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ekaitz-zarraga/8473daf2525717aa2013f9e0e66ad86d to your computer and use it in GitHub Desktop.
Save ekaitz-zarraga/8473daf2525717aa2013f9e0e66ad86d to your computer and use it in GitHub Desktop.
Robohydra frontend-dev-proxy to use with figwheel
var heads = require("robohydra").heads,
RoboHydraHeadProxy = heads.RoboHydraHeadProxy,
RoboHydraHeadFilesystem = heads.RoboHydraHeadFilesystem;
// Configuration variables:
// * urlfigwheel: url to proxy to figwheel
// * urlproxy: url to proxy
// * figwheelto: remote URL of the figwheel server. Defaults to 'http:localhost:3449'
// * proxyto: remote URL of the proxy.
// * sethostheader: if the "Host" header should be set to the URL the
// requests are proxied to. Defaults to yes, set to "no" to avoid it.
exports.getBodyParts = function(conf) {
"use strict";
if (conf.urlfigwheel === undefined) {
console.error("ERROR: Don't have any URL path to serve by figwheel\n" +
"(hint: pass the 'urlfigwheel' variable like " +
"'robohydra ... urlfigwheel=/')");
process.exit(1);
}
if (conf.figwheelto === undefined) {
conf.figwheelto = 'http://localhost:3449';
}
if (conf.urlproxy === undefined) {
console.error("ERROR: Don't have any remote URL to serve\n"+
"(hint: `urlproxy` variable like " +
"'robohydra ... urlproxy=api/')");
process.exit(1);
}
if (conf.proxyto === undefined) {
console.error("ERROR: I need a URL to proxy to!\n(hint: pass the " +
"'proxyto' like 'robohydra ... proxyto=http://...')");
process.exit(1);
}
var heads = [];
// Remote proxy
heads.push(new RoboHydraHeadProxy({
name: 'real-server-proxy',
mountPath: conf.urlproxy,
proxyTo: conf.proxyto,
setHostHeader: (conf.sethostheader !== 'no')
}));
// Figwheel proxy
heads.push(new RoboHydraHeadProxy({
name: 'figwheel-proxy',
mountPath: conf.urlfigwheel,
proxyTo: conf.figwheelto,
setHostHeader: (conf.sethostheader !== 'no')
}));
return {
heads: heads
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment