Files
2024-10-09 19:16:35 -06:00

47 lines
1.7 KiB
Markdown

# Url Shortener
## Implementation Details
I used Dart/Flutter to write the entire stack. Frontend is flutter compiled to web. Backend uses the [dart_frog](https://dartfrog.vgv.dev/) framework.
Architecture is a simple server that serves the static frontend files on `/` and requests to create shortened urls as well as the redirects.
Dart frog does file-based routing similar to Next.js. However, I was unable to get the static content served on `/` and get shortened urls to route to `/[slug]` so I added them to a sub-route `/u/[slug]`.
## How to Run
### Running with Docker (Simpler)
With docker installed, `cd` into the `new_backend/build/` directory where the `Dockerfile` is located. Build the docker image with
```sh
docker build -t <image_name> ./
```
Once built, run it with:
```sh
docker run -d -p 8080:8080 <image_name>
```
The container port is hard-coded, so you have to use the internal port 8080, the host can be whichever port.
### Running the local dev server
- [Install dart](https://dart.dev/get-dart)
- [Install dart_frog](https://dartfrog.vgv.dev/docs/overview)
Then run the backend with:
```sh
cd new_backend/ && dart pub get && dart_frog dev
```
## Testing
I wrote some unit tests to get the url shortening to work, and everything else was tested manually. I also include some asserts in the code to verify the various assumptions I made in the code.
## Tools Used
I used various documentation sites, like the one for the dart_frog web framework, as well as the [MDN docs for response codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status).
I discovered from asking an LLM that I could use the redirection status codes to do the url resolving, but otherwise referenced the docs to decide to use 308.