A simple reverse proxy for generating stripped-down, content-only, mobile-friendly sites.

Sven Slootweg 1628f4be61 Support X-Forwarded headers 1 year ago
.gitignore 19dcc18a45 Initial commit 1 year ago
README.md 19dcc18a45 Initial commit 1 year ago
load-config.js b080ec883b Make Babel preset paths absolute 1 year ago
package.json f17fbe24fe Add server.js as main binary 1 year ago
rewrite-html-urls.js 19dcc18a45 Initial commit 1 year ago
server.js 1628f4be61 Support X-Forwarded headers 1 year ago
yarn.lock c89479bd68 Update dependencies 1 year ago



A simple service that proxies and transforms content from one or more external sites, meant to be used for generating versions of websites that are friendly to low-powered/limited mobile devices.

Supports multiple external sites; the correct site to proxy will be picked depending on the hostname of the incoming request. So you need one 'subdomain' (DNS record) per site you want to proxy.

Keep in mind that this is not a general-purpose reverse proxy. While its behaviour is reasonably configurable, it's ultimately meant to generate stripped-down versions of sites, and to that end it may indiscriminately strip out rich content that a shoddily-designed or low-powered mobile device may not be able to deal with.

Rewrites URLs on-the-fly as needed to keep site-internal links pointing at the proxy, even when those links are expressed as absolute URLs. Currently no CSS URL rewriting; you probably won't be proxying any CSS anyway.


Create a config.jsx (yes, JSX) that looks something like this:

"use strict";

const React = require("react");
const url = require("url");

module.exports = {
	port: 3001,
	hosts: {
		"iomfats.cryto.net": {
			prefix: () => (
				<div style={{ color: "#801700" }}>
					This is a mobile proxy for the IOMfAtS Story Shelf.
			filters: [{
				matchPath: "/",
				mapUrl: "http://iomfats.org/storyshelf/",
				mapContent: ($) => $("div#homelinks").html()
			}, {
				mapUrl: ({path}) => url.resolve("http://iomfats.org/", path),
				mapContent: ($) => $("div#content").html()

You can use JSX like you normally would, but you cannot currently require external JSX files. You can require other JS modules, so long as you've installed them into the project first. The $ argument in a mapContent callback is a cheerio instance, the object passed to mapUrl comes from url.parse.

I might write more documentation later if somebody other than me actually ends up using this thing. If you get stuck on something, just file an issue for now with your question!

Running it

node server.js

Or if your configuration file is in a different location:

node server.js /path/to/config.jsx