Migrating event urls
Up until this point, My sense of aesthetics was stubbornly insisting on this URL structure:
https://photopaste.com/[event_slug]
instead of
https://photopaste.com/event/[event_slug]
https://photopaste.com/e/[event_slug]
https://events.photopaste.com/[event_slug]
... and I got away with it for years. If you define every other route before reaching the wildcard, it works pretty well. Catch everything in a wild card, make a call to the database to see if the event exists, then show the event. If it doesn't then show the 404.
Unfortunately this also means that everything that should be a 404 leads to an unnecessary DB call, which irritates my sense of efficiency.
After the introduction of SSR the problem got exaggerated. I wanted the server to generate custom meta tags for events. In order to do that, the server had to retrieve event metadata whenever a crawler visited an event URL. This led to API calls like /api/v2/events/robots.txt/meta that dutifully returned a 404 that showed up in my NodeJS server log, which infuriated me because I don't like unnecessary errors in my pristine log. Furthermore, due to the wildcard, the SSR compiler couldn't differentiate which pages it should pre-render.
So I gave up on my quest. I might have been able made it work with lots of glue and sticky tape, but I decided to bite the bullet and migrate.
Due to the way I had setup the routing system, it was easier than I thought. I had setup a dynamic baseUrl that was used to make it easy to navigate the same components in different base paths like /my-event/profile and /my-event/dashboard/profile. By changing the behavior at the root, most other components didn't need to change.
There were some snags and gotchas, like activation mails that still contained the old URL and server generated older versions that got cached, but in the end it works.
I also added a fallback mechanism to the 404 page that checks (only client side) if an old event URL is being used and redirects to the new style. I will remove that in due time.
Result
Events now follow the new URL style: https://photopaste.com/e/[event_slug]
Read more articles
- Moving towards Cloud storage
- Add event and user statistics
- Refactor Infrastructure
- Add QR code to mobile
- Video support and Scrolling Menu
- Automatic blog updates with Git Webhooks
- Add sliding sidebar menu to mobile home page
- I've been doing WebFlux wrong
- Implement Blog
- Migrating event urls
- Interesting bug
- Dynamic social media badges
- Improving Games and Teams
- Blue Green deployments
- Why I left the big cloud
- Moving from AWS Amplify to Google Firebase
- First version