fix: cannot correctly get client ip in /ping endpoint
This commit is contained in:
parent
26207171d6
commit
24e9d0e5c0
7
bun.lock
7
bun.lock
@ -1,5 +1,6 @@
|
||||
{
|
||||
"lockfileVersion": 1,
|
||||
"configVersion": 0,
|
||||
"workspaces": {
|
||||
"": {
|
||||
"name": "cvsa",
|
||||
@ -1127,7 +1128,7 @@
|
||||
|
||||
"bullmq": ["bullmq@5.65.0", "", { "dependencies": { "cron-parser": "^4.9.0", "ioredis": "^5.8.2", "msgpackr": "^1.11.2", "node-abort-controller": "^3.1.1", "semver": "^7.5.4", "tslib": "^2.0.0", "uuid": "^11.1.0" } }, "sha512-fyOcyf2ad4zrNmE18vdF/ie7DrW0TwhLt5e0DkqDxbRpDNiUdYqgp2QZJW2ntnUN08T2mDMC4deUUhF2UOAmeQ=="],
|
||||
|
||||
"bun-types": ["bun-types@1.3.3", "", { "dependencies": { "@types/node": "*" } }, "sha512-z3Xwlg7j2l9JY27x5Qn3Wlyos8YAp0kKRlrePAOjgjMGS5IG6E7Jnlx736vH9UVI4wUICwwhC9anYL++XeOgTQ=="],
|
||||
"bun-types": ["bun-types@1.3.4", "", { "dependencies": { "@types/node": "*" } }, "sha512-5ua817+BZPZOlNaRgGBpZJOSAQ9RQ17pkwPD0yR7CfJg+r8DgIILByFifDTa+IPDDxzf5VNhtNlcKqFzDgJvlQ=="],
|
||||
|
||||
"bytes": ["bytes@3.1.2", "", {}, "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg=="],
|
||||
|
||||
@ -2633,6 +2634,8 @@
|
||||
|
||||
"temp_frontend/@types/react/csstype": ["csstype@3.2.3", "", {}, "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ=="],
|
||||
|
||||
"tracker/@types/bun/bun-types": ["bun-types@1.3.3", "", { "dependencies": { "@types/node": "*" } }, "sha512-z3Xwlg7j2l9JY27x5Qn3Wlyos8YAp0kKRlrePAOjgjMGS5IG6E7Jnlx736vH9UVI4wUICwwhC9anYL++XeOgTQ=="],
|
||||
|
||||
"tracker/@types/node/undici-types": ["undici-types@6.21.0", "", {}, "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ=="],
|
||||
|
||||
"tracker/@types/react/csstype": ["csstype@3.2.3", "", {}, "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ=="],
|
||||
@ -2719,6 +2722,8 @@
|
||||
|
||||
"sucrase/glob/minimatch/brace-expansion": ["brace-expansion@2.0.2", "", { "dependencies": { "balanced-match": "^1.0.0" } }, "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ=="],
|
||||
|
||||
"tracker/@types/bun/bun-types/@types/node": ["@types/node@24.10.0", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-qzQZRBqkFsYyaSWXuEHc2WR9c0a0CXwiE5FWUvn7ZM+vdy1uZLfCunD38UzhuB7YN/J11ndbDBcTmOdxJo9Q7A=="],
|
||||
|
||||
"@react-router/serve/express/accepts/mime-types/mime-db": ["mime-db@1.52.0", "", {}, "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg=="],
|
||||
|
||||
"@react-router/serve/express/type-is/mime-types/mime-db": ["mime-db@1.52.0", "", {}, "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg=="],
|
||||
|
||||
@ -1,17 +1,18 @@
|
||||
import { VERSION } from "@backend/src";
|
||||
import { Elysia, t } from "elysia";
|
||||
import { ip } from "elysia-ip";
|
||||
|
||||
export const pingHandler = new Elysia({ prefix: "/ping" }).get(
|
||||
export const pingHandler = new Elysia({ prefix: "/ping" }).use(ip()).get(
|
||||
"/",
|
||||
async (c) => {
|
||||
async ({ headers, request, body, ip }) => {
|
||||
return {
|
||||
message: "pong",
|
||||
request: {
|
||||
headers: c.headers,
|
||||
ip: c.server?.requestIP(c.request)?.address,
|
||||
method: c.request.method,
|
||||
body: c.body,
|
||||
url: c.request.url
|
||||
headers: headers,
|
||||
ip: ip,
|
||||
method: request.method,
|
||||
body: body,
|
||||
url: request.url
|
||||
},
|
||||
response: {
|
||||
time: new Date().getTime(),
|
||||
|
||||
@ -42,9 +42,15 @@ async function getSongInfo(id: number) {
|
||||
}
|
||||
|
||||
export const songHandler = new Elysia({ prefix: "/song/:id" })
|
||||
.resolve(async ({ params }) => {
|
||||
.resolve(async ({ params, status }) => {
|
||||
const id = params.id;
|
||||
const songID = await getSongID(id);
|
||||
if (Number.isNaN(songID)) {
|
||||
return status(404, {
|
||||
code: "SONG_NOT_FOUND",
|
||||
message: "Given song cannot be found."
|
||||
});
|
||||
}
|
||||
return {
|
||||
songID
|
||||
};
|
||||
@ -52,12 +58,6 @@ export const songHandler = new Elysia({ prefix: "/song/:id" })
|
||||
.get(
|
||||
"/info",
|
||||
async ({ status, songID }) => {
|
||||
if (!songID) {
|
||||
return status(404, {
|
||||
code: "SONG_NOT_FOUND",
|
||||
message: "Given song cannot be found."
|
||||
});
|
||||
}
|
||||
const info = await getSongInfo(songID);
|
||||
if (!info) {
|
||||
return status(404, {
|
||||
@ -146,13 +146,7 @@ export const songHandler = new Elysia({ prefix: "/song/:id" })
|
||||
.use(requireAuth)
|
||||
.patch(
|
||||
"/info",
|
||||
async ({ params, status, body, user, songID }) => {
|
||||
if (!songID) {
|
||||
return status(404, {
|
||||
code: "SONG_NOT_FOUND",
|
||||
message: "Given song cannot be found."
|
||||
});
|
||||
}
|
||||
async ({ status, body, user, songID }) => {
|
||||
const info = await getSongInfo(songID);
|
||||
if (!info) {
|
||||
return status(404, {
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { Elysia, ErrorHandler, file } from "elysia";
|
||||
import { Elysia, ErrorHandler } from "elysia";
|
||||
import { getBindingInfo, logStartup } from "./startMessage";
|
||||
import { pingHandler } from "@backend/routes/ping";
|
||||
import openapi from "@elysiajs/openapi";
|
||||
import { cors } from "@elysiajs/cors";
|
||||
import { songHandler } from "@backend/routes/song/info";
|
||||
import { rootHandler } from "@backend/routes/root";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user