Parse URL query params
crookse opened this issue · 0 comments
crookse commented
Summary
What:
When connecting to the server, the URL query params should be parsable and usable by the user.
Why:
A use case came up in the Discord where a user asked if parsing query params was possible. Also, it allows more flexibility in handling connections. For example, if a user wanted to make their server auto connect a user to a certain channel based on a query param, they would be able to do that.
Acceptance Criteria
Below is a list of tasks that must be completed before this issue can be closed.
- URL query params are parsable in the event listener (see example pseudocode)
- Write documentation
- Write unit tests
- Write integration tests
Example Pseudo Code (for implementation)
const server = new Server(...)
await server.run(...)
const urlQueryParams: Record<string, string> = {};
server.on("connect", (packet) => {
const url = packet.from.url
const queryString = url.split("?")[1]
if (queryString) {
const parts = queryString.split("&")
for (const part of parts) {
const [name, value] = part.split("=")
urlQueryParams[name] = value
}
}
})
console.log(server.queryParams) // {}, not set yet
server.on("join", () => {
console.log(server.queryParams) // { "path": "someValue" }
})