1
0
Fork 0
A simple reverse proxy for generating stripped-down, content-only, mobile-friendly sites.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
Sven Slootweg 1628f4be61 Support X-Forwarded headers vor 5 Jahren
.gitignore Initial commit vor 5 Jahren
README.md Initial commit vor 5 Jahren
load-config.js Make Babel preset paths absolute vor 5 Jahren
package.json Add server.js as main binary vor 5 Jahren
rewrite-html-urls.js Initial commit vor 5 Jahren
server.js Support X-Forwarded headers vor 5 Jahren
yarn.lock Update dependencies vor 5 Jahren

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