mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-12 12:04:16 +00:00
improve server handlers
This commit is contained in:
parent
87b17582ce
commit
b6b51e5d7f
@ -10,7 +10,7 @@ import axios from "axios"
|
|||||||
import routes from "./routes"
|
import routes from "./routes"
|
||||||
|
|
||||||
const mainAPI = axios.create({
|
const mainAPI = axios.create({
|
||||||
baseURL: process.env.MAIN_API_URL ?? "http://localhost:3000",
|
baseURL: process.NODE_ENV === "production" ? (process.env.MAIN_API_URL) : (process.env.DEV_API_URL ?? "http://localhost:3010"),
|
||||||
headers: {
|
headers: {
|
||||||
"server_token": `${process.env.MAIN_SERVER_ID}:${process.env.MAIN_SERVER_TOKEN}`,
|
"server_token": `${process.env.MAIN_SERVER_ID}:${process.env.MAIN_SERVER_TOKEN}`,
|
||||||
}
|
}
|
||||||
@ -71,10 +71,16 @@ class TextRoomServer {
|
|||||||
return res.data
|
return res.data
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
console.error(`[${socket.id}] failed to validate session caused by server error`, err)
|
||||||
|
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!session || !session?.valid) {
|
if (!session) {
|
||||||
|
return next(new Error(`auth:server_error`))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (session.invalid) {
|
||||||
return next(new Error(`auth:token_invalid`))
|
return next(new Error(`auth:token_invalid`))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,8 +93,6 @@ class TextRoomServer {
|
|||||||
return null
|
return null
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(userData)
|
|
||||||
|
|
||||||
if (!userData) {
|
if (!userData) {
|
||||||
return next(new Error(`auth:user_failed`))
|
return next(new Error(`auth:user_failed`))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user