A simple reverse proxy for generating stripped-down, content-only, mobile-friendly sites.
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
Sven Slootweg 1628f4be61 Support X-Forwarded headers 5 anni fa
.gitignore Initial commit 5 anni fa
README.md Initial commit 5 anni fa
load-config.js Make Babel preset paths absolute 5 anni fa
package.json Add server.js as main binary 5 anni fa
rewrite-html-urls.js Initial commit 5 anni fa
server.js Support X-Forwarded headers 5 anni fa
yarn.lock Update dependencies 5 anni fa

README.md

mobile-proxy

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.

Configuration

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.
				</div>
			),
			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