mirror of
https://github.com/Yonle/bostr.git
synced 2025-09-29 14:22:38 +02:00
@@ -57,7 +57,7 @@ module.exports = (ws, req) => {
|
|||||||
JSON.stringify(["NOTICE", "error: bad JSON."])
|
JSON.stringify(["NOTICE", "error: bad JSON."])
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
console.log(data)
|
||||||
switch (data[0]) {
|
switch (data[0]) {
|
||||||
case "EVENT":
|
case "EVENT":
|
||||||
if (!authorized) return;
|
if (!authorized) return;
|
||||||
|
@@ -102,6 +102,9 @@ module.exports = {
|
|||||||
"version": require("./package.json").version
|
"version": require("./package.json").version
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Path to favicon file.
|
||||||
|
favicon: "",
|
||||||
|
|
||||||
// Cache relays
|
// Cache relays
|
||||||
// Used for caching received events from <relays> to reduce bandwidth waste.
|
// Used for caching received events from <relays> to reduce bandwidth waste.
|
||||||
// Keeping this empty will disable caching function.
|
// Keeping this empty will disable caching function.
|
||||||
|
6
http.js
6
http.js
@@ -2,6 +2,7 @@ const { version } = require("./package.json");
|
|||||||
const WebSocket = require("ws");
|
const WebSocket = require("ws");
|
||||||
const config = require("./config");
|
const config = require("./config");
|
||||||
const http = require("http");
|
const http = require("http");
|
||||||
|
const fs = require("fs");
|
||||||
const bouncer = require(`./bouncer.js`);
|
const bouncer = require(`./bouncer.js`);
|
||||||
|
|
||||||
// For log
|
// For log
|
||||||
@@ -13,6 +14,8 @@ const server = http.createServer({ noDelay: true })
|
|||||||
const wss = new WebSocket.WebSocketServer({ noServer: true });
|
const wss = new WebSocket.WebSocketServer({ noServer: true });
|
||||||
const lastConn = new Map();
|
const lastConn = new Map();
|
||||||
|
|
||||||
|
const favicon = fs.existsSync(config.favicon) ? fs.readFileSync(config.favicon) : null;
|
||||||
|
|
||||||
server.on('request', (req, res) => {
|
server.on('request', (req, res) => {
|
||||||
log(`${req.headers["x-forwarded-for"]?.split(",")[0] || req.socket.address()?.address} - ${req.method} ${req.url} [${req.headers["user-agent"] || ""}]`)
|
log(`${req.headers["x-forwarded-for"]?.split(",")[0] || req.socket.address()?.address} - ${req.method} ${req.url} [${req.headers["user-agent"] || ""}]`)
|
||||||
|
|
||||||
@@ -35,6 +38,9 @@ server.on('request', (req, res) => {
|
|||||||
if (config?.authorized_keys?.length) res.write("\nNOTE: This relay has configured for personal use only. Only authorized users could use this bostr relay.\n");
|
if (config?.authorized_keys?.length) res.write("\nNOTE: This relay has configured for personal use only. Only authorized users could use this bostr relay.\n");
|
||||||
res.write(`\nConnect to this bouncer with nostr client: ws://${req.headers.host}${req.url} or wss://${req.headers.host}${req.url}\n\n---\n`);
|
res.write(`\nConnect to this bouncer with nostr client: ws://${req.headers.host}${req.url} or wss://${req.headers.host}${req.url}\n\n---\n`);
|
||||||
res.end(`Powered by Bostr (${version}) - Open source Nostr bouncer\nhttps://github.com/Yonle/bostr`);
|
res.end(`Powered by Bostr (${version}) - Open source Nostr bouncer\nhttps://github.com/Yonle/bostr`);
|
||||||
|
} else if (req.url.startsWith("/favicon") && favicon) {
|
||||||
|
res.writeHead(200, { "Content-Type": "image/" + config.favicon?.split(".").pop() });
|
||||||
|
res.end(favicon);
|
||||||
} else {
|
} else {
|
||||||
res.writeHead(404).end("What are you looking for?");
|
res.writeHead(404).end("What are you looking for?");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user