Sven Slootweg 1628f4be61 | 5 years ago | |
---|---|---|
.gitignore | 5 years ago | |
README.md | 5 years ago | |
load-config.js | 5 years ago | |
package.json | 5 years ago | |
rewrite-html-urls.js | 5 years ago | |
server.js | 5 years ago | |
yarn.lock | 5 years ago |
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