Update customBare.mjs
This commit is contained in:
parent
f96aaf1a06
commit
8a0099a6cf
1 changed files with 48 additions and 22 deletions
|
|
@ -1,14 +1,19 @@
|
||||||
import fetch from 'node-fetch';
|
import fetch from 'node-fetch';
|
||||||
import { URL } from 'url';
|
import { URL } from 'url';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
import * as csstree from 'css-tree';
|
||||||
|
import * as ws from 'ws';
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
prefix: "/service",
|
prefix: "/service",
|
||||||
requireSSL: true, // Requires SSL?
|
requireSSL: true, // Requires SSL?
|
||||||
proxy: {
|
defaultHeaders: {
|
||||||
host: "162.159.134.234",
|
'X-Content-Type-Options': 'no-sniff',
|
||||||
port: "443"
|
},
|
||||||
} //HTTP Proxy
|
//proxy: {
|
||||||
|
// host: "3.211.17.212",
|
||||||
|
// port: "80"
|
||||||
|
//} // HTTP Proxy
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.requireSSL) {
|
if (config.requireSSL) {
|
||||||
|
|
@ -24,11 +29,11 @@ function rewriteJavascript(js) {
|
||||||
return javascript
|
return javascript
|
||||||
}
|
}
|
||||||
|
|
||||||
function insertScript(html, origin) {
|
function insertScript(html) {
|
||||||
var res = `<!DOCTYPE html>
|
var res = `<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<script preload type="module" src="/cyclone.js"></script>
|
<script preload src="/cyclone/cyclone.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
${html}
|
${html}
|
||||||
|
|
@ -39,15 +44,13 @@ ${html}
|
||||||
|
|
||||||
async function fetchBare(url, res, req) {
|
async function fetchBare(url, res, req) {
|
||||||
try {
|
try {
|
||||||
var origin = 'https' + "://" + req.rawHeaders[1];
|
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
method: req.method,
|
method: req.method,
|
||||||
headers: {
|
headers: {
|
||||||
|
"Refer": url.href,
|
||||||
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36",
|
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36",
|
||||||
cookies: req.cookies
|
"cookies": req.cookies,
|
||||||
},
|
},
|
||||||
credentials: "same-origin"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -61,19 +64,25 @@ async function fetchBare(url, res, req) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
var contentType = request.headers.get('content-type') || 'application/javascript'
|
var contentType = request.headers.get('content-type') || 'application/javascript'
|
||||||
|
} catch {
|
||||||
|
var contentType = 'application/javascript';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (url.href.endsWith('.js')||url.href.endsWith(".js")) contentType = "application/javascript";
|
||||||
|
if (url.href.endsWith('.css')||url.href.endsWith(".css")) contentType = "text/css";
|
||||||
|
|
||||||
var output = null;
|
var output = null;
|
||||||
|
|
||||||
if (contentType.includes('html') || contentType.includes('javascript')) {
|
if (contentType.includes('html') || contentType.includes('javascript')) {
|
||||||
var doc = await request.text();
|
var doc = await request.text();
|
||||||
}
|
}
|
||||||
|
|
||||||
res.writeHead(200, "Sucess", {
|
res.setHeader('content-type', contentType);
|
||||||
"content-type": contentType
|
|
||||||
})
|
|
||||||
|
|
||||||
if (contentType.includes('html')) {
|
if (contentType.includes('html')) {
|
||||||
output = insertScript(doc, origin);
|
output = insertScript(doc);
|
||||||
res.write(output);
|
res.write(output);
|
||||||
res.end();
|
res.end();
|
||||||
} else if (contentType.includes('javascript')) {
|
} else if (contentType.includes('javascript')) {
|
||||||
|
|
@ -87,25 +96,29 @@ async function fetchBare(url, res, req) {
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
|
res.writeHead(500, 'Error', {
|
||||||
|
'content-type': 'application/javascript'
|
||||||
|
})
|
||||||
res.end(e)
|
res.end(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function websocketIntercept(req,res) {
|
||||||
|
console.log(req);
|
||||||
|
}
|
||||||
|
|
||||||
function route(req, res) {
|
function route(req, res) {
|
||||||
var path = req.url;
|
var path = req.url;
|
||||||
|
|
||||||
if (isBare(req,res)) {
|
if (path.startsWith(config.prefix + "/")) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var url = new URL(path.split(config.prefix + "/")[1])
|
var url = new URL(path.split(config.prefix + "/")[1])
|
||||||
} catch {
|
} catch {
|
||||||
var url = new URL("https://" + path.split(config.prefix + "/")[1])
|
var url = new URL("https://" + path.split(config.prefix + "/")[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchBare(url, res, req);
|
fetchBare(url, res,req);
|
||||||
|
|
||||||
return true;
|
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -115,7 +128,20 @@ function isBare(req, res) {
|
||||||
return (req.url.startsWith(config.prefix));
|
return (req.url.startsWith(config.prefix));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function routeSocket(req, socket) {
|
||||||
|
var path = req.url;
|
||||||
|
|
||||||
|
try {
|
||||||
|
var url = new URL(path.split(config.prefix + "/")[1])
|
||||||
|
} catch {
|
||||||
|
var url = new URL("wss://" + path.split(config.prefix + "/")[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(url);
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
route,
|
route,
|
||||||
isBare
|
routeSocket,
|
||||||
|
isBare,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue