Initial commit 🍀

This commit is contained in:
syuilo
2016-12-29 07:49:51 +09:00
commit b3f42e62af
405 changed files with 31017 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
import * as url from 'url';
import * as express from 'express';
import * as request from 'request';
module.exports = (req: express.Request, res: express.Response) => {
const _url = req.params.url;
if (!_url) {
return;
}
request({
url: _url + url.parse(req.url, true).search,
encoding: null
}, (err, response, content) => {
if (err) {
console.error(err);
return;
}
const contentType = response.headers['content-type'];
if (/^text\//.test(contentType) || contentType === 'application/javascript') {
content = content.toString().replace(/http:\/\//g, `${config.secondary_scheme}://proxy.${config.secondary_host}/http://`);
}
res.header('Content-Type', contentType);
res.send(content);
});
};

View File

@@ -0,0 +1,17 @@
/**
* Forward Proxy Service
*/
import * as express from 'express';
import * as cors from 'cors';
/**
* Init app
*/
const app = express();
app.disable('x-powered-by');
app.use(cors());
app.get('/:url(*)', require('./proxy'));
module.exports = app;

View File

@@ -0,0 +1,16 @@
import * as express from 'express';
import * as request from 'request';
const xml2json = require('xml2json');
module.exports = (req: express.Request, res: express.Response) => {
const url: string = req.body.url;
request(url, (err, response, xml) => {
if (err) {
console.error(err);
return;
}
res.send(xml2json.toJson(xml));
});
};

View File

@@ -0,0 +1,13 @@
import * as express from 'express';
import summaly from 'summaly';
module.exports = async (req: express.Request, res: express.Response) => {
const summary = await summaly(req.query.url);
summary.icon = wrap(summary.icon);
summary.thumbnail = wrap(summary.thumbnail);
res.send(summary);
};
function wrap(url: string): string {
return `${config.proxy_url}/${url}`;
}