Skip to content

Commit 5aa6128

Browse files
committed
🎉 initial commit
0 parents  commit 5aa6128

31 files changed

+1504
-0
lines changed

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
TURSO_CONNECTION_URL=""
2+
TURSO_AUTH_TOKEN=""
3+
API_KEY=""
4+
API_URL=""

.github/workflows/deploy.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Deploy to VPS
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build_and_push:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout the repo
13+
uses: actions/checkout@v4
14+
15+
- name: Login to Dockerhub
16+
uses: docker/login-action@v3
17+
with:
18+
username: ${{ secrets.DOCKERHUB_USERNAME }}
19+
password: ${{ secrets.DOCKERHUB_TOKEN }}
20+
21+
- name: Build and push Docker image
22+
run: |
23+
docker build --platform linux/amd64 -t axlz/link-manager-api .
24+
docker push axlz/link-manager-api
25+
26+
- name: Send compose.yml to VPS
27+
uses: appleboy/scp-action@master
28+
with:
29+
host: ${{ secrets.HOST }}
30+
username: ${{ secrets.USERNAME }}
31+
password: ${{ secrets.PASSWORD }}
32+
port: ${{ secrets.PORT }}
33+
source: "compose.yml"
34+
target: "/home/${{ secrets.USERNAME }}/link-manager-api"
35+
36+
- name: Deploy to VPS
37+
uses: appleboy/ssh-action@master
38+
with:
39+
host: ${{ secrets.HOST }}
40+
username: ${{ secrets.USERNAME }}
41+
password: ${{ secrets.PASSWORD }}
42+
port: ${{ secrets.PORT }}
43+
script: |
44+
docker pull axlz/link-manager-api
45+
cd link-manager-api
46+
touch .env
47+
echo "${{ secrets.ENV_FILE }}" > .env
48+
docker compose up -d --build --force-recreate

.gitignore

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env.local
29+
.env.development.local
30+
.env.test.local
31+
.env.production.local
32+
.env
33+
34+
# vercel
35+
.vercel
36+
37+
**/*.trace
38+
**/*.zip
39+
**/*.tar.gz
40+
**/*.tgz
41+
**/*.log
42+
package-lock.json
43+
**/*.bun
44+
public

Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM oven/bun
2+
3+
WORKDIR /app
4+
5+
COPY package.json .
6+
COPY bun.lockb .
7+
8+
RUN bun install --production
9+
10+
COPY src src
11+
COPY tsconfig.json .
12+
# COPY public public
13+
14+
ENV NODE_ENV production
15+
CMD ["bun", "src/index.ts"]
16+
17+
EXPOSE 3500

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
> This is the back-end of my personal link manager. The front-end is available [here](https://github.com/axeelz/link-manager-dashboard).
2+
3+
## General
4+
5+
- [Presentation](https://axlz.me/why) - Learn more about the project
6+
7+
---
8+
9+
# Elysia with Bun runtime
10+
11+
## Getting Started
12+
13+
To run this application you need to have the [Bun CLI installed](https://bun.sh/)
14+
15+
## Development
16+
17+
To start the development server run:
18+
19+
```bash
20+
bun run dev
21+
```
22+
23+
Open http://localhost:3000/ with your browser to see the result.
24+
25+
## Database
26+
27+
This uses SQLite with Turso and Drizzle ORM.
28+
29+
Launch Drizzle Studio with:
30+
31+
```bash
32+
npx drizzle-kit studio
33+
```
34+
35+
Generate a migration with:
36+
37+
```bash
38+
npx drizzle-kit generate:sqlite
39+
```
40+
41+
Run the migration with:
42+
43+
```bash
44+
npx drizzle-kit push:sqlite
45+
```

bun.lockb

70.8 KB
Binary file not shown.

compose.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
services:
2+
server:
3+
ports:
4+
- "127.0.0.1:3500:3500"
5+
image: "axlz/link-manager-api"
6+
env_file:
7+
- .env
8+
platform: linux/amd64

drizzle.config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import "dotenv/config";
2+
import type { Config } from "drizzle-kit";
3+
4+
export default {
5+
schema: "./src/db/schema.ts",
6+
out: "./migrations",
7+
driver: "turso",
8+
dbCredentials: {
9+
url: process.env.TURSO_CONNECTION_URL!,
10+
authToken: process.env.TURSO_AUTH_TOKEN!,
11+
},
12+
} satisfies Config;

migrations/0000_clear_the_phantom.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CREATE TABLE `links` (
2+
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
3+
`code` text NOT NULL,
4+
`url` text NOT NULL,
5+
`redirects` integer DEFAULT 0,
6+
`created_at` integer DEFAULT (unixepoch()) NOT NULL
7+
);
8+
--> statement-breakpoint
9+
CREATE UNIQUE INDEX `links_code_unique` ON `links` (`code`);

migrations/0001_crazy_night_nurse.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CREATE TABLE `redirects` (
2+
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
3+
`link_id` integer,
4+
`location` text,
5+
`language` text,
6+
`referrer` text,
7+
`user_agent` text,
8+
`created_at` integer DEFAULT (unixepoch()) NOT NULL,
9+
FOREIGN KEY (`link_id`) REFERENCES `links`(`id`) ON UPDATE no action ON DELETE cascade
10+
);

migrations/0002_plain_the_spike.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
SQLite does not support "Set not null to column" out of the box, we do not generate automatic migration for that, so it has to be done manually
3+
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
4+
https://www.sqlite.org/lang_altertable.html
5+
https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3
6+
7+
Due to that we don't generate migration automatically and it has to be done manually
8+
*/

migrations/meta/0000_snapshot.json

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"version": "5",
3+
"dialect": "sqlite",
4+
"id": "60302bca-324e-435b-a48b-3f42eacef676",
5+
"prevId": "00000000-0000-0000-0000-000000000000",
6+
"tables": {
7+
"links": {
8+
"name": "links",
9+
"columns": {
10+
"id": {
11+
"name": "id",
12+
"type": "integer",
13+
"primaryKey": true,
14+
"notNull": true,
15+
"autoincrement": true
16+
},
17+
"code": {
18+
"name": "code",
19+
"type": "text",
20+
"primaryKey": false,
21+
"notNull": true,
22+
"autoincrement": false
23+
},
24+
"url": {
25+
"name": "url",
26+
"type": "text",
27+
"primaryKey": false,
28+
"notNull": true,
29+
"autoincrement": false
30+
},
31+
"redirects": {
32+
"name": "redirects",
33+
"type": "integer",
34+
"primaryKey": false,
35+
"notNull": false,
36+
"autoincrement": false,
37+
"default": 0
38+
},
39+
"created_at": {
40+
"name": "created_at",
41+
"type": "integer",
42+
"primaryKey": false,
43+
"notNull": true,
44+
"autoincrement": false,
45+
"default": "(unixepoch())"
46+
}
47+
},
48+
"indexes": {
49+
"links_code_unique": {
50+
"name": "links_code_unique",
51+
"columns": [
52+
"code"
53+
],
54+
"isUnique": true
55+
}
56+
},
57+
"foreignKeys": {},
58+
"compositePrimaryKeys": {},
59+
"uniqueConstraints": {}
60+
}
61+
},
62+
"enums": {},
63+
"_meta": {
64+
"schemas": {},
65+
"tables": {},
66+
"columns": {}
67+
}
68+
}

0 commit comments

Comments
 (0)