Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/derrickmehaffy/strapi-test-redirect
Sample Strapi application that is built to show how you can create a simple URL Shortener
https://github.com/derrickmehaffy/strapi-test-redirect
Last synced: 2 days ago
JSON representation
Sample Strapi application that is built to show how you can create a simple URL Shortener
- Host: GitHub
- URL: https://github.com/derrickmehaffy/strapi-test-redirect
- Owner: derrickmehaffy
- Created: 2021-08-23T21:26:57.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-08-23T21:29:47.000Z (about 3 years ago)
- Last Synced: 2024-10-16T07:21:20.066Z (22 days ago)
- Language: JavaScript
- Size: 185 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Strapi URL Shortener / Redirect
This is a sample Strapi application that is built to show how you can create a simple URL Shortener using built in koa redirect methods.
There is a single model with the following fields:
- `name`: Used to give simple names to shortened links
- `short_code`: The shortened code that users will use to be redirected
- `redirect_url`: This is the URL the user will be redirected toIf for some reason a user tries to request a code that doesn't exist then the user is redirected to `https://strapi.io/404`
In order for this to work, a new route is added to a normal model that has a different prefix route, though this could be customized, it would not be a good idea to bind this on the root path. In this example it's bound to `/r/:short_code` in the [following file](api/redirect/config/routes.json#L27-L34).
Adding new routes is very simple, as the name can be anything you want (the user doesn't see this), a unique short code (enforced since it's a UID), and a redirect URL.
Additionally the [custom controller](api/redirect/controllers/redirect.js) could also send telemetry data to an external service.