Skip to content

Commit d696d64

Browse files
committed
Normalize paths
1 parent fffd9ad commit d696d64

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

serve.py

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ async def home(request: web.Request):
5050
return web.Response(text=content, content_type='text/html')
5151

5252

53-
@routes.get('/auctions/')
53+
@routes.get('/auctions')
5454
async def get_current_auctions(request: web.Request):
5555
page = int(request.query.get("page", 1))
5656
filters = tibiapy.AuctionFilters()
@@ -88,7 +88,7 @@ async def get_auction(request: web.Request):
8888
return json_response(response)
8989

9090

91-
@routes.get('/creatures/')
91+
@routes.get('/creatures')
9292
async def get_library_creatures(request: web.Request):
9393
response = await app["tibiapy"].fetch_library_creatures()
9494
return json_response(response)
@@ -107,7 +107,7 @@ async def get_library_creature(request: web.Request):
107107
return json_response(response)
108108

109109

110-
@routes.get('/events/')
110+
@routes.get('/events')
111111
@routes.get('/events/{year}/{month}')
112112
async def get_event_schedule(request: web.Request):
113113
year = request.match_info.get('year')
@@ -120,7 +120,7 @@ async def get_event_schedule(request: web.Request):
120120
return json_response(response)
121121

122122

123-
@routes.get('/cmposts/{start_date}/{end_date}/')
123+
@routes.get('/cmposts/{start_date}/{end_date}')
124124
async def get_cm_post_archive(request: web.Request):
125125
start_date_str = request.match_info['start_date']
126126
end_date_str = request.match_info['end_date']
@@ -131,25 +131,25 @@ async def get_cm_post_archive(request: web.Request):
131131
return json_response(response)
132132

133133

134-
@routes.get('/forums/community/')
134+
@routes.get('/forums/community')
135135
async def get_community_boards(request: web.Request):
136136
response = await app["tibiapy"].fetch_forum_community_boards()
137137
return json_response(response)
138138

139139

140-
@routes.get('/forums/support/')
140+
@routes.get('/forums/support')
141141
async def get_support_boards(request: web.Request):
142142
response = await app["tibiapy"].fetch_forum_support_boards()
143143
return json_response(response)
144144

145145

146-
@routes.get('/forums/world/')
146+
@routes.get('/forums/world')
147147
async def get_world_boards(request: web.Request):
148148
response = await app["tibiapy"].fetch_forum_world_boards()
149149
return json_response(response)
150150

151151

152-
@routes.get('/forums/trade/')
152+
@routes.get('/forums/trade')
153153
async def get_trade_boards(request: web.Request):
154154
response = await app["tibiapy"].fetch_forum_trade_boards()
155155
return json_response(response)
@@ -177,21 +177,21 @@ async def get_forum_post_html(request: web.Request):
177177
return web.Response(text=response.data.anchored_post.content, content_type="text/html")
178178

179179

180-
@routes.get('/forums/announcement/{announcement_id}/')
180+
@routes.get('/forums/announcement/{announcement_id}')
181181
async def get_forum_announcement(request: web.Request):
182182
announcement_id = request.match_info['announcement_id']
183183
response = await app["tibiapy"].fetch_forum_announcement(int(announcement_id))
184184
return json_response(response)
185185

186186

187-
@routes.get('/forums/announcement/{announcement_id}/html/')
187+
@routes.get('/forums/announcement/{announcement_id}/html')
188188
async def get_forum_announcement_html(request: web.Request):
189189
announcement_id = request.match_info['announcement_id']
190190
response = await app["tibiapy"].fetch_forum_announcement(int(announcement_id))
191191
return json_response(response)
192192

193193

194-
@routes.get('/forums/board/{board_id}/')
194+
@routes.get('/forums/board/{board_id}')
195195
async def get_board_threads(request: web.Request):
196196
board_id = request.match_info['board_id']
197197
page = int(request.query.get("page", 1))
@@ -200,35 +200,35 @@ async def get_board_threads(request: web.Request):
200200
return json_response(response)
201201

202202

203-
@routes.get('/characters/{name}/')
203+
@routes.get('/characters/{name}')
204204
async def get_character(request: web.Request):
205205
name = request.match_info['name']
206206
response = await app["tibiapy"].fetch_character(name)
207207
return json_response(response)
208208

209209

210-
@routes.get('/guilds/{name}/')
210+
@routes.get('/guilds/{name}')
211211
async def get_guild(request: web.Request):
212212
name = request.match_info['name']
213213
response = await app["tibiapy"].fetch_guild(name)
214214
return json_response(response)
215215

216216

217-
@routes.get('/guilds/{name}/wars/')
217+
@routes.get('/guilds/{name}/wars')
218218
async def get_guild_wars(request: web.Request):
219219
name = request.match_info['name']
220220
response = await app["tibiapy"].fetch_guild_wars(name)
221221
return json_response(response)
222222

223223

224-
@routes.get('/worlds/{name}/guilds/')
224+
@routes.get('/worlds/{name}/guilds')
225225
async def get_world_guilds(request: web.Request):
226226
name = request.match_info['name']
227227
response = await app["tibiapy"].fetch_world_guilds(name)
228228
return json_response(response)
229229

230230

231-
@routes.get(r'/highscores/{world}/')
231+
@routes.get(r'/highscores/{world}')
232232
async def get_highscores(request: web.Request):
233233
world = request.match_info['world']
234234
category = try_enum(tibiapy.Category, request.query.get("category", "EXPERIENCE").upper(), tibiapy.Category.EXPERIENCE)
@@ -244,7 +244,7 @@ async def get_highscores(request: web.Request):
244244
return json_response(response)
245245

246246

247-
@routes.get('/houses/{world}/{town}/')
247+
@routes.get('/houses/{world}/{town}')
248248
async def get_houses(request: web.Request):
249249
world = request.match_info['world']
250250
town = request.match_info['town']
@@ -255,35 +255,35 @@ async def get_houses(request: web.Request):
255255
return json_response(response)
256256

257257

258-
@routes.get('/house/{world}/{house_id}/')
258+
@routes.get('/house/{world}/{house_id}')
259259
async def get_house(request: web.Request):
260260
world = request.match_info['world']
261261
house_id = request.match_info['house_id']
262262
response = await app["tibiapy"].fetch_house(int(house_id), world)
263263
return json_response(response)
264264

265265

266-
@routes.get('/killstatistics/{world}/')
266+
@routes.get('/killstatistics/{world}')
267267
async def get_kill_statistics(request: web.Request):
268268
world = request.match_info['world']
269269
response = await app["tibiapy"].fetch_kill_statistics(world)
270270
return json_response(response)
271271

272272

273-
@routes.get('/worlds/')
273+
@routes.get('/worlds')
274274
async def get_worlds(request: web.Request):
275275
response = await app["tibiapy"].fetch_world_list()
276276
return json_response(response)
277277

278278

279-
@routes.get('/worlds/{name}/')
279+
@routes.get('/worlds/{name}')
280280
async def get_world(request: web.Request):
281281
name = request.match_info['name']
282282
response = await app["tibiapy"].fetch_world(name)
283283
return json_response(response)
284284

285285

286-
@routes.get('/news/recent/')
286+
@routes.get('/news/recent')
287287
@routes.get('/news/recent/{days}')
288288
async def get_recent_news(request: web.Request):
289289
days = request.match_info.get("days")
@@ -295,14 +295,14 @@ async def get_recent_news(request: web.Request):
295295
return json_response(response)
296296

297297

298-
@routes.get('/news/{news_id}/')
298+
@routes.get('/news/{news_id}')
299299
async def get_news(request: web.Request):
300300
news_id = request.match_info['news_id']
301301
response = await app["tibiapy"].fetch_news(int(news_id))
302302
return json_response(response)
303303

304304

305-
@routes.get('/news/{news_id}/html/')
305+
@routes.get('/news/{news_id}/html')
306306
async def get_news_html(request: web.Request):
307307
news_id = request.match_info['news_id']
308308
response = await app["tibiapy"].fetch_news(int(news_id))
@@ -312,14 +312,14 @@ async def get_news_html(request: web.Request):
312312
return web.HTTPNotFound()
313313

314314

315-
@routes.get('/tournaments/{tournament_id}/')
315+
@routes.get('/tournaments/{tournament_id}')
316316
async def get_tournaments(request: web.Request):
317317
tournament_id = request.match_info['tournament_id']
318318
response = await app["tibiapy"].fetch_tournament(int(tournament_id))
319319
return json_response(response)
320320

321321

322-
@routes.get('/tournaments/{tournament_id}/leaderboards/{world}/{page}/')
322+
@routes.get('/tournaments/{tournament_id}/leaderboards/{world}/{page}')
323323
async def get_tournaments_leaderboard(request: web.Request):
324324
tournament_id = request.match_info['tournament_id']
325325
world = request.match_info['world']
@@ -360,8 +360,10 @@ async def init_client(app):
360360
app["tibiapy"] = tibiapy.Client()
361361

362362
if __name__ == "__main__":
363-
normalize_paths = normalize_path_middleware()
364-
app = web.Application(middlewares=[error_middleware, normalize_paths])
363+
normalize_paths = normalize_path_middleware(remove_slash=True, append_slash=False)
364+
app = web.Application(middlewares=[
365+
error_middleware,
366+
normalize_paths])
365367
app.add_routes(routes)
366368
app.on_startup.append(init_client)
367369
print("Registered routes:")

0 commit comments

Comments
 (0)