Initial commit 🍀
This commit is contained in:
30
src/web/service/proxy/proxy.ts
Normal file
30
src/web/service/proxy/proxy.ts
Normal 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);
|
||||
});
|
||||
};
|
17
src/web/service/proxy/server.ts
Normal file
17
src/web/service/proxy/server.ts
Normal 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;
|
16
src/web/service/rss-proxy.ts
Normal file
16
src/web/service/rss-proxy.ts
Normal 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));
|
||||
});
|
||||
};
|
13
src/web/service/url-preview.ts
Normal file
13
src/web/service/url-preview.ts
Normal 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}`;
|
||||
}
|
Reference in New Issue
Block a user