makefile and update dependencies

This commit is contained in:
Elijah McMorris 2024-08-03 01:41:29 +00:00
parent 2d2a4a4c07
commit 509508990e
Signed by: NexVeridian
SSH key fingerprint: SHA256:bsA1SKZxuEcEVHAy3gY1HUeM5ykRJl0U0kQHQn0hMg8
14 changed files with 1050 additions and 1439 deletions

View file

@ -18,7 +18,14 @@
"features": {
"ghcr.io/devcontainers/features/git:1": {},
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/nix:1": {}
"ghcr.io/devcontainers/features/nix:1": {
"packages": [
"btop",
"lazygit",
"nixpkgs-fmt"
],
"extraNixConfig": "experimental-features = nix-command flakes"
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

View file

@ -9,7 +9,11 @@
.env
.gitignore
Cargo.lock
docker-compose.dev.yml
docker-compose.yml
docker-compose-postgres.yml
docker-compose-postgres.dev.yml
docker-compose-surrealdb.yml
docker-compose-surrealdb.dev.yml
Makefile
Dockerfile
*.md
shell.nix

View file

@ -6,8 +6,8 @@
- [docker-compose-postgres.dev.yml](./docker-compose-postgres.dev.yml)
- [docker-compose-surrealdb.dev.yml](./docker-compose-surrealdb.dev.yml)
#### Then run:
- `docker compose -f docker-compose-postgres.dev.yml up --pull always -d`
- `docker compose -f docker-compose-surrealdb.dev.yml up --pull always -d`
- `make up-postgres.dev`
- `make up-surrealdb.dev`
## Dev Containers
Install docker, vscode and the [Dev Containers Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
@ -20,7 +20,7 @@ Install docker, vscode and the [Dev Containers Extension](https://marketplace.vi
`nix-shell`
`npx npm-check-updates -u`
`npx npm-check-updates -u && npm i --package-lock-only`
# License
All code in this repository is dual-licensed under either [License-MIT](./LICENSE-MIT) or [LICENSE-APACHE](./LICENSE-Apache) at your option. This means you can select the license you prefer. [Why dual license](https://github.com/bevyengine/bevy/issues/2373)

11
Makefile Normal file
View file

@ -0,0 +1,11 @@
COMPOSE_FILES := postgres surrealdb postgres.dev surrealdb.dev
.PHONY: $(addprefix up-,$(COMPOSE_FILES)) $(addprefix down-,$(COMPOSE_FILES))
$(addprefix up-,$(COMPOSE_FILES)):
make down-$(subst up-,,$@)
docker compose -f docker-compose-$(subst up-,,$@).yml up --build --pull always -d
$(addprefix down-,$(COMPOSE_FILES)):
docker compose -f docker-compose-$(subst down-,,$@).yml down --volumes --remove-orphans
docker network prune -f

View file

@ -1,5 +1,5 @@
# next-url-shortener
A simple URL shortener using [Next.js](https://nextjs.org/) 14 server actions, [Postgres](https://www.postgresql.org/) or [SurrealDB](https://surrealdb.com/), [Shadcn/ui](http://ui.shadcn.com/) and [Tailwind](https://tailwindcss.com/).
A URL shortener using [Next.js](https://nextjs.org/) 14 server actions, [Postgres](https://www.postgresql.org/) or [SurrealDB](https://surrealdb.com/), [Shadcn/ui](http://ui.shadcn.com/) and [Tailwind](https://tailwindcss.com/).
# Install
### Copy one
@ -9,16 +9,22 @@ A simple URL shortener using [Next.js](https://nextjs.org/) 14 server actions, [
Create data folder next to docker-compose.yml and .env, and set the data type in .env
```
├── data
│ ├── postgres
│ └── surrealdb
├── Makefile
├── docker-compose-postgres.yml
└── .env
```
### Then run:
- `docker compose -f docker-compose-postgres.yml up --pull always -d`
- `docker compose -f docker-compose-surrealdb.yml up --pull always -d`
- `make up-postgres`
- `make up-surrealdb`
### Then exit with:
- `make down-postgres`
- `make down-surrealdb`
## Example .env
```
```shell
# postgres or surrealdb
DB_TYPE=postgres
@ -35,7 +41,8 @@ POSTGRES_DB=url
DB_USER=root
DB_PASSWORD=root
OVERRIDE_URL=s.nexv.dev
# Enter your website url here
# OVERRIDE_URL=s.nexv.dev
```
# License

View file

@ -1,36 +1,35 @@
version: "3"
services:
next-url-shortener:
container_name: next-url-shortener
build: .
env_file:
- .env
ports:
- 3000:3000
depends_on:
- postgres
networks:
- postgres
next-url-shortener:
container_name: next-url-shortener
build: .
env_file:
- .env
ports:
- 3000:3000
depends_on:
- postgres
networks:
- postgres
postgres:
container_name: postgres
image: postgres:latest
env_file:
- .env
restart: always
deploy:
resources:
reservations:
cpus: 1
ports:
- 5432:5432
volumes:
- ./data/postgres:/var/lib/postgresql/data
networks:
- postgres
postgres:
container_name: postgres
image: postgres:latest
env_file:
- .env
restart: always
deploy:
resources:
reservations:
cpus: 1.0
ports:
- 5432:5432
volumes:
- ./data/postgres:/var/lib/postgresql/data
networks:
- postgres
volumes:
data:
data:
networks:
postgres:
postgres:

View file

@ -1,36 +1,35 @@
version: "3"
services:
next-url-shortener:
container_name: next-url-shortener
image: ghcr.io/nexveridian/next-url-shortener:latest
env_file:
- .env
ports:
- 3000:3000
depends_on:
- postgres
networks:
- postgres
next-url-shortener:
container_name: next-url-shortener
image: ghcr.io/nexveridian/next-url-shortener:latest
env_file:
- .env
ports:
- 3000:3000
depends_on:
- postgres
networks:
- postgres
postgres:
container_name: postgres
image: postgres:latest
env_file:
- .env
restart: always
deploy:
resources:
reservations:
cpus: 1
ports:
- 5432:5432
volumes:
- ./data/postgres:/var/lib/postgresql/data
networks:
- postgres
postgres:
container_name: postgres
image: postgres:latest
env_file:
- .env
restart: always
deploy:
resources:
reservations:
cpus: 1.0
ports:
- 5432:5432
volumes:
- ./data/postgres:/var/lib/postgresql/data
networks:
- postgres
volumes:
data:
data:
networks:
postgres:
postgres:

View file

@ -1,43 +1,50 @@
version: "3"
services:
nextjs:
build: .
env_file:
- .env
ports:
- "3000:3000"
depends_on:
- surrealdb
networks:
- surrealdb
nextjs:
container_name: next-url-shortener
build: .
env_file:
- .env
ports:
- 3000:3000
depends_on:
- surrealdb
networks:
surrealdb:
# ipv4_address: 172.20.0.2
surrealdb:
container_name: surrealdb
image: surrealdb/surrealdb:latest-dev
env_file:
- .env
entrypoint:
- /surreal
- start
- --user
- $DB_USER
- --pass
- $DB_PASSWORD
- file:/data/surrealdb
restart: always
deploy:
resources:
reservations:
cpus: "1"
ports:
- 8000:8000
volumes:
- ./data:/data
networks:
- surrealdb
surrealdb:
container_name: surrealdb
image: surrealdb/surrealdb:v2.0.0-alpha.9
env_file:
- .env
entrypoint:
- /surreal
- start
- --user
- $DB_USER
- --pass
- $DB_PASSWORD
- file:/data/surrealdb
user: root
restart: always
deploy:
resources:
reservations:
cpus: 1.0
ports:
- 8000:8000
volumes:
- ./data:/data
networks:
surrealdb:
# ipv4_address: 172.20.0.1
volumes:
data:
data:
networks:
surrealdb:
surrealdb:
# ipam:
# config:
# - subnet: 172.20.0.0/16
# gateway: 172.20.0.254

View file

@ -1,44 +1,43 @@
version: "3"
services:
next-url-shortener:
container_name: next-url-shortener
image: ghcr.io/nexveridian/next-url-shortener:latest
env_file:
- .env
ports:
- 3000:3000
depends_on:
- surrealdb
networks:
- surrealdb
next-url-shortener:
container_name: next-url-shortener
image: ghcr.io/nexveridian/next-url-shortener:latest
env_file:
- .env
ports:
- 3000:3000
depends_on:
- surrealdb
networks:
- surrealdb
surrealdb:
container_name: surrealdb
image: surrealdb/surrealdb:latest-dev
env_file:
- .env
entrypoint:
- /surreal
- start
- --user
- $DB_USER
- --pass
- $DB_PASSWORD
- file:/data/surrealdb
restart: always
deploy:
resources:
reservations:
cpus: 1
ports:
- 8000:8000
volumes:
- ./data:/data
networks:
- surrealdb
surrealdb:
container_name: surrealdb
image: surrealdb/surrealdb:v2.0.0-alpha.9
env_file:
- .env
entrypoint:
- /surreal
- start
- --user
- $DB_USER
- --pass
- $DB_PASSWORD
- file:/data/surrealdb
restart: always
deploy:
resources:
reservations:
cpus: 1.0
ports:
- 8000:8000
volumes:
- ./data:/data
networks:
- surrealdb
volumes:
data:
data:
networks:
surrealdb:
surrealdb:

2108
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -9,42 +9,42 @@
"lint": "next lint"
},
"dependencies": {
"@hookform/resolvers": "^3.4.2",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@hookform/resolvers": "^3.9.0",
"@radix-ui/react-dropdown-menu": "^2.1.1",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-navigation-menu": "^1.1.4",
"@radix-ui/react-popover": "^1.0.7",
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-slot": "^1.0.2",
"@tanstack/react-table": "^8.17.3",
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-navigation-menu": "^1.2.0",
"@radix-ui/react-popover": "^1.1.1",
"@radix-ui/react-select": "^2.1.1",
"@radix-ui/react-slot": "^1.1.0",
"@tanstack/react-table": "^8.20.1",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"dotenv": "^16.4.5",
"next": "14.2.3",
"next": "14.2.5",
"next-themes": "^0.3.0",
"postgres": "^3.4.4",
"react": "^18.3.1",
"react-hook-form": "^7.51.5",
"surrealdb.js": "^0.11.1",
"react-hook-form": "^7.52.2",
"surrealdb.js": "^1.0.0-beta.18",
"swr": "^2.2.5",
"tailwind-merge": "^2.3.0",
"tailwind-merge": "^2.4.0",
"tailwindcss-animate": "^1.0.7",
"ws": "^8.17.0",
"ws": "^8.18.0",
"zod": "^3.23.8"
},
"devDependencies": {
"@types/node": "^20",
"@types/node": "^22",
"@types/prop-types": "^15.7.12",
"@types/react": "^18.3.3",
"@types/react-dom": "^18",
"autoprefixer": "^10.4.19",
"autoprefixer": "^10.4.20",
"eslint": "^8",
"eslint-config-next": "14.2.3",
"eslint-config-next": "14.2.5",
"postcss": "^8",
"prettier": "^3.3.0",
"prettier-plugin-tailwindcss": "^0.6.1",
"tailwindcss": "^3.4.3",
"prettier": "^3.3.3",
"prettier-plugin-tailwindcss": "^0.6.5",
"tailwindcss": "^3.4.7",
"typescript": "^5"
}
}

View file

@ -5,14 +5,11 @@ export async function querydb(slug: string) {
let long_url = undefined;
try {
if (process.env.DB_TYPE === "surrealdb") {
let db = await initConnectionSurreal();
let long_url = await db.query(`
long_url = await db.query(`
update url:[$id]
set clicks = clicks + 1;
select * from url:[$id];
set clicks +=1;
`, { id: slug });
// @ts-ignore
long_url = long_url[0][0].long_url;
}

View file

@ -17,7 +17,8 @@ export async function querydb(prevState: any, formData: FormData) {
if (!values.success) {
return { error: values.error };
}
const long_url = values.data.url;
let long_url = values.data.url.replace("https://", "").replace("http://", "");
long_url = long_url.endsWith('/') ? long_url.slice(0, -1) : long_url;
let url = undefined;
try {
@ -31,7 +32,7 @@ export async function querydb(prevState: any, formData: FormData) {
date_accessed: <future> { time::now() }
} return id[0];
`, {
long_url: long_url.replace("https://", "").replace("http://", "")
long_url: long_url
});
// @ts-ignore
url = url[0][0].id;
@ -54,7 +55,7 @@ export async function querydb(prevState: any, formData: FormData) {
insert into url (id, long_url, clicks, date_added, date_accessed)
values (
${generateRandomString(8)},
${long_url.replace("https://", "").replace("http://", "")},
${long_url},
0,
now(),
now()

View file

@ -5,7 +5,7 @@ const db = new Surreal();
export async function initConnectionSurreal(): Promise<Surreal> {
try {
db.connect("ws://" + process.env.DB_URL_PORT + "/rpc", {
await db.connect("ws://" + process.env.DB_URL_PORT + "/rpc", {
namespace: "url",
database: "url",
auth: {