mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-17 03:14:40 -05:00
reformat file
This commit is contained in:
parent
118b4e54d4
commit
c8ef0ab022
1 changed files with 25 additions and 28 deletions
39
p/server.js
39
p/server.js
|
@ -1,51 +1,48 @@
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const express = require('express');
|
const express = require("express");
|
||||||
const fetch = require('node-fetch');
|
const fetch = require("node-fetch");
|
||||||
const htmlParser = require("node-html-parser");
|
const htmlParser = require("node-html-parser");
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
app.use(express.json()) // for parsing application/json
|
app.use(express.json()); // for parsing application/json
|
||||||
app.use(express.urlencoded({ extended: true })) // for parsing application/x-www-form-urlencoded
|
app.use(express.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
|
||||||
|
|
||||||
let Proxy = async (req, res) => {
|
let Proxy = async (req, res) => {
|
||||||
var url = req.originalUrl
|
const url = "https://" + req.originalUrl.slice(10);
|
||||||
|
|
||||||
let f = await fetch(url, {
|
let f = await fetch(url, {
|
||||||
method: req.method,
|
method: req.method,
|
||||||
});
|
});
|
||||||
if(false && f.headers.get('content-type').includes("html")){
|
if (false && f.headers.get("content-type").includes("html")) {
|
||||||
const body = await f.text();
|
const body = await f.text();
|
||||||
if(false && !htmlParser.valid(body)) {
|
if (false && !htmlParser.valid(body)) {
|
||||||
console.warn(`[ERROR] Invalid HTML at ${url}`);
|
console.warn(`[ERROR] Invalid HTML at ${url}`);
|
||||||
f.body.pipe(res);
|
f.body.pipe(res);
|
||||||
return;
|
return;
|
||||||
};
|
}
|
||||||
const root = htmlParser.parse(body);
|
const root = htmlParser.parse(body);
|
||||||
let html = root.childNodes.filter((x) => x.tagName && x.tagName.toLowerCase() == "html")[0];
|
let html = root.childNodes.filter(
|
||||||
|
(x) => x.tagName && x.tagName.toLowerCase() == "html"
|
||||||
|
)[0];
|
||||||
|
|
||||||
if(!html) {
|
if (!html) {
|
||||||
console.warn(`[ERROR] No <html> at ${url}`);
|
console.warn(`[ERROR] No <html> at ${url}`);
|
||||||
res.send(body);
|
res.send(body);
|
||||||
return;
|
return;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
res.send(html.toString());
|
res.send(html.toString());
|
||||||
} else {
|
} else {
|
||||||
f.body.pipe(res);
|
f.body.pipe(res);
|
||||||
};
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const listener = (req, res) => {
|
const listener = (req, res) => {
|
||||||
Proxy(req, res)
|
Proxy(req, res);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
app.get("/", (req, res) => res.redirect(`/https://www.google.com/`));
|
app.get("/", (req, res) => res.redirect(`/https://www.google.com/`));
|
||||||
app.all('/*', listener);
|
app.all("/*", listener);
|
||||||
|
|
||||||
|
app.listen(3000, () => {});
|
||||||
app.listen(3000, () => {
|
|
||||||
})
|
|
||||||
|
|
Loading…
Reference in a new issue