Implement X-Forwarded-For
This commit is contained in:
parent
3ef51d525d
commit
c9dccd0f38
2
public
2
public
|
@ -1 +1 @@
|
|||
Subproject commit 0f21e390667589f7acfef4d82a8f270a830822ee
|
||||
Subproject commit 6d894d19cd7dbe09f9fdf65cd954b916326c4437
|
|
@ -56,11 +56,11 @@ export class Socket extends EventEmitter {
|
|||
private cursorPos: Vector2<CursorValue> = { x: 200, y: 100 };
|
||||
|
||||
constructor(
|
||||
private ws: ServerWebSocket<unknown>,
|
||||
private ws: ServerWebSocket<{ ip: string }>,
|
||||
public socketID: string
|
||||
) {
|
||||
super();
|
||||
this.ip = ws.remoteAddress; // Participant ID
|
||||
this.ip = ws.data.ip;
|
||||
|
||||
// User ID
|
||||
this._id = createUserID(this.getIP());
|
||||
|
|
|
@ -31,11 +31,20 @@ async function getIndex() {
|
|||
return response;
|
||||
}
|
||||
|
||||
export const app = Bun.serve({
|
||||
export const app = Bun.serve<{ ip: string }>({
|
||||
port: env.PORT,
|
||||
hostname: "0.0.0.0",
|
||||
fetch: (req, server) => {
|
||||
if (server.upgrade(req)) {
|
||||
const reqip = server.requestIP(req);
|
||||
if (!reqip) return;
|
||||
|
||||
if (
|
||||
server.upgrade(req, {
|
||||
data: {
|
||||
ip: req.headers.get("X-Forwarded-For") || reqip.address
|
||||
}
|
||||
})
|
||||
) {
|
||||
return;
|
||||
} else {
|
||||
const url = new URL(req.url).pathname;
|
||||
|
|
Loading…
Reference in New Issue