Skip to content

Commit

Permalink
[server][client] Changes room pattern from :id-:name to :id/:name
Browse files Browse the repository at this point in the history
Because `-` is allowed in URLs and in names for servers, I was seeing routing
issues with rooms that had dashes in their names. I don't have direct control
over the Mint router (unless I fork Mint) to change whether it uses eg greedy vs
non-greedy matching on routes, so I think the way to avoid this is to change the
room patern (this commit) and then URLencode room names (to handle cases where
rooms have eg a slash in their name; left for later work)
  • Loading branch information
Ryan Prior committed Nov 21, 2021
1 parent fc46bf7 commit 46ff334
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions client/source/Main.mint
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ routes {
}
}

/room/:id-:name?key=:key (id: String, name: String, key: String) {
/room/:id/:name?key=:key (id: String, name: String, key: String) {
try {
Application.initialize()
Application.acceptInvite({room = {id = id, name = name}, key = key})
Window.navigate("/room/#{id}-#{name}")
Window.navigate("/room/#{id}/#{name}")
Result::Ok(id)
} catch Storage.Error => error {
Result::Err(error)
}
}

/room/:id-:name (id: String, name: String) {
/room/:id/:name (id: String, name: String) {
sequence {
Application.initialize()
Messages.loadForRoom(id)
Expand Down
4 changes: 2 additions & 2 deletions client/source/Rooms.mint
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ component Rooms {
|> Maybe.toResult("")
data = decode object as RoomKey
Application.acceptInvite(data)
Window.navigate("/room/#{data.room.id}-#{data.room.name}")
Window.navigate("/room/#{data.room.id}/#{data.room.name}")
} catch Http.ErrorResponse => error {
sequence {
Debug.log(error)
Expand Down Expand Up @@ -90,7 +90,7 @@ component Rooms {
"Join a room"
<ul>
for (roomKey of data) {
<li><a href="/room/#{roomKey.room.id}-#{roomKey.room.name}"><{ roomKey.room.name }></a></li>
<li><a href="/room/#{roomKey.room.id}/#{roomKey.room.name}"><{ roomKey.room.name }></a></li>
}
</ul>
<a::createRoom(true) href="#" onClick={startCreating}>"+ Create a room"</a>
Expand Down
2 changes: 1 addition & 1 deletion client/source/Top.mint
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ component Top {
|> Maybe.toResult("")
data = decode object as RoomKey
next {
currentInvite = Maybe::Just("#{protocol}://#{`window.location.host`}/room/#{data.room.id}-#{data.room.name}?key=#{data.key}")
currentInvite = Maybe::Just("#{protocol}://#{`window.location.host`}/room/#{data.room.id}/#{data.room.name}?key=#{data.key}")
}
Result::Ok(response.body)
} catch Http.ErrorResponse => error {
Expand Down
2 changes: 1 addition & 1 deletion server/src/server.cr
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ get "/" do |env|
send_file env, "public/index.html"
end

get "/room/:id-:name" do |env|
get "/room/:id/:name" do |env|
send_file env, "public/index.html"
end

Expand Down

0 comments on commit 46ff334

Please sign in to comment.