Compare commits

...

2 Commits

Author SHA1 Message Date
e96c5f6820 log http 2025-02-14 13:36:10 -08:00
bb37ae81a4 handle error 2025-02-14 13:27:28 -08:00

19
u2b.js
View File

@ -1,7 +1,9 @@
var singleflightCache = {};
const timeoutMs = 1000*60*60*6;
require("http").createServer(async function (req, res) {
async function handle(req, res) {
console.log(new Date().toISOString(), req.socket.remoteAddress, req.headers["x-forwarded-for"] || '-', req.method, req.url, req.headers["user-agent"] || '-');
if (req.url == "/") {
res.writeHead(302, {"Location": "https://www.u2b.cx/"});
res.end();
@ -75,8 +77,7 @@ require("http").createServer(async function (req, res) {
"Expires": new Date((promise?.date?.valueOf() || Date.now()) + timeoutMs).toUTCString()
});
res.end();
}).listen(process.env.PORT || 8494, process.env.ADDRESS);
}
async function videoIdsFromYouTubeSearch(query) {
console.log("search", query);
@ -95,3 +96,15 @@ async function videoIdsFromYouTubeSearch(query) {
.filter(x => x.videoRenderer)
.map(x => x.videoRenderer.videoId);
}
require("http").createServer((req, res) => {
handle(req, res).catch(error => {
console.error(req.url, error.stack);
try {
res.writeHead(500);
res.end();
} catch (error) {
console.error(error.stack);
}
});
}).listen(process.env.PORT || 8494, process.env.ADDRESS);