Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/benjammin4dayz/shortlink
Self-hostable link shortener
https://github.com/benjammin4dayz/shortlink
api docker documented link-shortener mvc self-hosted shortener-service url-shortener
Last synced: about 2 months ago
JSON representation
Self-hostable link shortener
- Host: GitHub
- URL: https://github.com/benjammin4dayz/shortlink
- Owner: benjammin4dayz
- License: mit
- Created: 2024-08-08T21:59:28.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-08-09T12:10:37.000Z (5 months ago)
- Last Synced: 2024-08-10T03:39:09.416Z (5 months ago)
- Topics: api, docker, documented, link-shortener, mvc, self-hosted, shortener-service, url-shortener
- Language: JavaScript
- Homepage:
- Size: 74.2 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ShortLink
Simple, straightforward, self-hostable link shortener service built on SQLite, Express, and Node.js
Loosely inspired by ulvis.net
## Getting Started
After starting the service using one of the methods outlined below, the web UI can be used to start generating shortlinks without writing any code. Simply input the full URL you want to shorten into the form, click the button, and copy the output.
By default, the Express server will run on port `3000` unless `PORT` is specified in the .env file.
### Docker
Images are available on [Docker Hub](https://hub.docker.com/r/benjammin4dayz/shortlink/tags)
- **Example using docker run**
```bash
docker run -v data:/app/data -p 3000:3000 benjammin4dayz/shortlink
```- **Example using docker compose**
```yaml
version: '3.9'
services:
app:
image: benjammin4dayz/shortlink
ports:
- 3000:3000
volumes:
- data:/app/data
```### Source
Check the [tags](https://github.com/benjammin4dayz/shortlink/tags) for a specific version
- **Running the development server**
```bash
npm start
```- **Building for production**
```bash
npm run build
node dist/app.js
```## Shortener API
### GET /api/v1/shorten?url=``
_Content Type: `text/plain`_
Postfixing a query string with the `url=` parameter is the simplest way to interact with the API. If the provided URL is valid, a shortlink is returned in plain text. Otherwise, an empty string is returned.
**Request Format**
```js
fetch('/api/v1/shorten?url=https://example.com').then(res => res.text());
```### POST /api/v1/shorten
_Content Type: `application/json`_
This method accepts and returns an object with some more insight for use in your application
**Request Format**
```js
fetch('/api/v1/shorten', {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
method: 'POST',
body: JSON.stringify({
url: '',
}),
}).then(res => res.json());
```**Success Response**
```json
{
"message": "URL created successfully",
"data": {
"url": ""
}
}
```**Failure Response**
```json
{ "error": "That wasn't supposed to happen!" }
```