|
本帖最后由 hbghlyj 于 2022-9-5 14:46 编辑 - #!/usr/bin/env node
- "use strict";
- var http = require('http');
- http.createServer(function (client_req, client_res) {
- console.log('serve: ' + client_req.url);
- const options = {
- hostname: 'kuing.infinityfreeapp.com',
- path: client_req.url,
- method: client_req.method,
- headers: {
- 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0',
- 'cookie':'__test=bf16be7e1cad023ea994c34ab6f950cb;'
- }
- };
- http.request(options, function (response) {
- let headers = response.headers;
- if(headers['location'])
- headers['location']=headers['location'].replace('kuing.infinityfreeapp.com','cjhb.site:3001');
- switch(response.headers['content-type'].slice(0,9)){
- case 'text/html':
- client_res.writeHead(response.statusCode, headers);
- var str = '';
- response.on('data', function (chunk) {
- str += chunk;
- });
- response.on('end', function () {
- client_res.end(str.replaceAll('src="https://kuing.cjhb.site','src="http://cjhb.site:3001'));
- });
- break;
- case 'text/css':
- var str = '';
- response.on('data', function (chunk) {
- str += chunk;
- });
- response.on('end', function () {
- str = str.replaceAll('kuing.infinityfreeapp.com','cjhb.site:3001').replace(/url\(([^"\)]+)/g,'url("$1"');
- if(headers['content-length'])
- headers['content-length']=Buffer.byteLength(str);
- client_res.writeHead(response.statusCode, headers);
- client_res.end(str);
- });
- break;
- default:
- client_res.writeHead(response.statusCode, headers);
- response.pipe(client_res, {end: true});
- }
- }).end();
- }).listen(3001);
复制代码 注 |
|