Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/squiidz/fork
https://github.com/squiidz/fork
Last synced: 23 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/squiidz/fork
- Owner: squiidz
- Created: 2021-07-16T03:24:48.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-07-19T16:50:06.000Z (over 3 years ago)
- Last Synced: 2024-06-21T01:56:56.884Z (5 months ago)
- Language: Go
- Size: 333 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# fork URL shortener
test it here -> https://fork.pw### Build
#### backend
You need an google cloud platform account with firestore enable.https://firebase.google.com/docs/firestore/quickstart#go
- `export GOOGLE_APPLICATION_CREDENTIALS=path/to/credentials.json`
- `cd path/to/clone/fork`
- `go build`
- `./fork`
runs on port 8080 by default#### frontend
- `cd path/to/clone/fork/fork-ui`
- `npm run serve`go to http://localhost:8081
### Project structure
The project is split into two parts, the backend which is written in Go, and the frontend in Vuejs 3. The frontend part is pretty simple since it's only used for ease of testing. For the backend, it uses firestore as a DB and global counter management.### Infrastructure
The project is host in two separated parts, the frontend is on google cloud storage (which doesn't provide TLS) with Cloudflare in front to upgrade the connection to HTTPS. For the backend, it's on google cloud run with CD enable when pushing on the main branch of the git project.### Architecture
For the short link id, I've used base62 encoding since there's less chance for collision than md5 and also added an atomic global counter which is in firestore, so that multiple instances of the service can run simultaneously without generating the same short id. I've also use cloud run so that I don't have to scale manually if the service was getting a lot of traffic, but one downside is that after some time the first request can be a little bit longer to respond since it needs to startup the container first. But if it was a real service with constant traffic it probably won't be a problem.### Frontend usage
![Alt Text](https://storage.googleapis.com/www.fork.pw/fork-recording.gif)## API
The API consists of 4 primary endpoints.- `/gen-link` is use to generate new link, it needs a json payload with the url you want to shortened.
It accepts `POST, OPTIONS` methods.
```json
{ "url": "https://www.google.com" }
```
- `/update-link` is use for updating an existing link with a new url, it also needs a json payload.
It accepts `POST, OPTIONS` methods.
``` json
{"shortUrl": "https://fork.pw/aBre3", "newUrl": "https://github.com"}
```
- `/info-link/{id}` returns the info about an existing link, `{id}` needs to be replace with a short url id.
- It accepts `GET` method.
``` console
curl -XGET https://fork.pw/info-link/yBbPUt
```
- `/{id}` redirects the short link to the long url. `{id}` needs to be replace with a short url id.
In case that the upstream site is down it will fallback to a WaybackMachine snapshot.
It accept `GET` method.
``` console
curl -XGET https://fork.pw/yBbPUt
```