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": { "features": {
"ghcr.io/devcontainers/features/git:1": {}, "ghcr.io/devcontainers/features/git:1": {},
"ghcr.io/devcontainers/features/docker-in-docker:2": {}, "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. // Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [], // "forwardPorts": [],

View file

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

View file

@ -6,8 +6,8 @@
- [docker-compose-postgres.dev.yml](./docker-compose-postgres.dev.yml) - [docker-compose-postgres.dev.yml](./docker-compose-postgres.dev.yml)
- [docker-compose-surrealdb.dev.yml](./docker-compose-surrealdb.dev.yml) - [docker-compose-surrealdb.dev.yml](./docker-compose-surrealdb.dev.yml)
#### Then run: #### Then run:
- `docker compose -f docker-compose-postgres.dev.yml up --pull always -d` - `make up-postgres.dev`
- `docker compose -f docker-compose-surrealdb.dev.yml up --pull always -d` - `make up-surrealdb.dev`
## Dev Containers ## Dev Containers
Install docker, vscode and the [Dev Containers Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-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` `nix-shell`
`npx npm-check-updates -u` `npx npm-check-updates -u && npm i --package-lock-only`
# License # 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) 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 # 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 # Install
### Copy one ### 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 Create data folder next to docker-compose.yml and .env, and set the data type in .env
``` ```
├── data ├── data
│ ├── postgres
│ └── surrealdb │ └── surrealdb
├── Makefile
├── docker-compose-postgres.yml ├── docker-compose-postgres.yml
└── .env └── .env
``` ```
### Then run: ### Then run:
- `docker compose -f docker-compose-postgres.yml up --pull always -d` - `make up-postgres`
- `docker compose -f docker-compose-surrealdb.yml up --pull always -d` - `make up-surrealdb`
### Then exit with:
- `make down-postgres`
- `make down-surrealdb`
## Example .env ## Example .env
``` ```shell
# postgres or surrealdb # postgres or surrealdb
DB_TYPE=postgres DB_TYPE=postgres
@ -35,7 +41,8 @@ POSTGRES_DB=url
DB_USER=root DB_USER=root
DB_PASSWORD=root DB_PASSWORD=root
OVERRIDE_URL=s.nexv.dev # Enter your website url here
# OVERRIDE_URL=s.nexv.dev
``` ```
# License # License

View file

@ -1,4 +1,3 @@
version: "3"
services: services:
next-url-shortener: next-url-shortener:
container_name: next-url-shortener container_name: next-url-shortener
@ -21,7 +20,7 @@ services:
deploy: deploy:
resources: resources:
reservations: reservations:
cpus: 1 cpus: 1.0
ports: ports:
- 5432:5432 - 5432:5432
volumes: volumes:

View file

@ -1,4 +1,3 @@
version: "3"
services: services:
next-url-shortener: next-url-shortener:
container_name: next-url-shortener container_name: next-url-shortener
@ -21,7 +20,7 @@ services:
deploy: deploy:
resources: resources:
reservations: reservations:
cpus: 1 cpus: 1.0
ports: ports:
- 5432:5432 - 5432:5432
volumes: volumes:

View file

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

View file

@ -1,4 +1,3 @@
version: "3"
services: services:
next-url-shortener: next-url-shortener:
container_name: next-url-shortener container_name: next-url-shortener
@ -14,7 +13,7 @@ services:
surrealdb: surrealdb:
container_name: surrealdb container_name: surrealdb
image: surrealdb/surrealdb:latest-dev image: surrealdb/surrealdb:v2.0.0-alpha.9
env_file: env_file:
- .env - .env
entrypoint: entrypoint:
@ -29,7 +28,7 @@ services:
deploy: deploy:
resources: resources:
reservations: reservations:
cpus: 1 cpus: 1.0
ports: ports:
- 8000:8000 - 8000:8000
volumes: volumes:

2108
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

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

View file

@ -5,14 +5,11 @@ export async function querydb(slug: string) {
let long_url = undefined; let long_url = undefined;
try { try {
if (process.env.DB_TYPE === "surrealdb") { if (process.env.DB_TYPE === "surrealdb") {
let db = await initConnectionSurreal(); let db = await initConnectionSurreal();
let long_url = await db.query(` long_url = await db.query(`
update url:[$id] update url:[$id]
set clicks = clicks + 1; set clicks +=1;
select * from url:[$id];
`, { id: slug }); `, { id: slug });
// @ts-ignore // @ts-ignore
long_url = long_url[0][0].long_url; 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) { if (!values.success) {
return { error: values.error }; 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; let url = undefined;
try { try {
@ -31,7 +32,7 @@ export async function querydb(prevState: any, formData: FormData) {
date_accessed: <future> { time::now() } date_accessed: <future> { time::now() }
} return id[0]; } return id[0];
`, { `, {
long_url: long_url.replace("https://", "").replace("http://", "") long_url: long_url
}); });
// @ts-ignore // @ts-ignore
url = url[0][0].id; 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) insert into url (id, long_url, clicks, date_added, date_accessed)
values ( values (
${generateRandomString(8)}, ${generateRandomString(8)},
${long_url.replace("https://", "").replace("http://", "")}, ${long_url},
0, 0,
now(), now(),
now() now()

View file

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