Dynamic pages, a pretty interesting feature. Here's just a very small snippet of how we generate one of these pages. We get a connection to the database, and we render the page. By the end of that method, you should have a fully rendered Lou detail panel for your mobile device.
In terms of moving the API over, it was originally offered using the express framework. Luckily, Next makes it super simple to take something like that over across to their platform. In terms of GraphQL, which we use as a front on top of our Mongo database, most of it was left largely unchanged, so this is what the architecture looks like now. Where the GraphQL plus the Next.js parts lives would have been the express server, but now Next has kind of subsumed that Create React app and we've managed to put it all on the same level stack. We've also added this nice little addition of a Redis cache layer, which means that when a user requests a map tile, we first check in our cache, and if it's there, we will give them that instead. This is what Aloo looks like. It's kind of evolved over many years, so the shape of it isn't perfect, but it does the job, and very quickly, this is how you grab Aloo from our GraphQL resolver, and in terms of running the GraphQL server, we connect to our database, we start Apollo server, and you have your API root.
In terms of authentication, we were originally using Auth0, and we still are. In fact, Next makes it a dream to handle. They provide a high order component, and we could wrap one of our routes with that, and everything worked as expected. So, another key part of this work was improving the overall user experience of the project. So, that was all around actually the mechanics of moving from create react app to Next. These are some things we did as on top of that to really just make the site better for everyone. The first thing we did was we took the size of an object for an individual loop down from a pretty big blob of JSON, around 260 bytes into a single string. And we're very quickly gonna look at the anatomy of that string and how we're able to represent pretty much exactly the same information in a small amount of space.
So, if we break that string down, you'll see that it's make up of the lose ID which is unique. A geohash and a filter. Before I started this, I had no idea what a geohash was, and we'll dive into that briefly. But first of all, we're gonna have a look at how we optimize these filters. So, as a user of the map, you have these switches, and they allow you to filter by various criteria. It's a kind of useful feature. These are easily represented using just bits. Part of a binary number I'm sure you're familiar with. And that was quite a good realization, because it meant that all of a sudden, we could represent the state of these switches using those bits. And that's important, because we went from a fairly large piece of information to just a single number to represent any combination of those filters we wanted to. So, in this demonstration, we've got the very first bit highlighted, which means it's a no payment toilet.
Comments