generated from pure_sagacity/turborepo-starter-project
added realtime, bruno stuff, and removed s3/redis
removed zod because elysia has it built in changed compose.yml to docker-compose.yml because my icon shows it as docker-compose that way
This commit is contained in:
@@ -27,6 +27,9 @@ out/
|
|||||||
build
|
build
|
||||||
dist
|
dist
|
||||||
|
|
||||||
|
# Environment Variables
|
||||||
|
.env*
|
||||||
|
!.env.example
|
||||||
|
|
||||||
# Debug
|
# Debug
|
||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "next dev -p 5173",
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
"lint": "biome check",
|
"lint": "biome check",
|
||||||
@@ -48,4 +48,4 @@
|
|||||||
"sharp",
|
"sharp",
|
||||||
"unrs-resolver"
|
"unrs-resolver"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
import { RedisClient } from "bun";
|
|
||||||
|
|
||||||
type RedisOptions = {
|
|
||||||
url: string;
|
|
||||||
options?: Bun.RedisOptions;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Redis {
|
|
||||||
private client: RedisClient;
|
|
||||||
|
|
||||||
constructor(options: RedisOptions) {
|
|
||||||
this.client = new RedisClient(options.url, options.options);
|
|
||||||
}
|
|
||||||
|
|
||||||
async set(key: string, value: string, expireInSeconds?: number) {
|
|
||||||
if (expireInSeconds) {
|
|
||||||
await this.client.set(key, value, "EX", expireInSeconds);
|
|
||||||
} else {
|
|
||||||
await this.client.set(key, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async get<T>(key: string): Promise<T | null> {
|
|
||||||
const value = await this.client.get(key);
|
|
||||||
return value ? (JSON.parse(value) as T) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
async del(key: string) {
|
|
||||||
await this.client.del(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
async exists(key: string): Promise<boolean> {
|
|
||||||
return await this.client.exists(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const redis = new Redis({
|
|
||||||
url: process.env.REDIS_URL || "redis://localhost:6379",
|
|
||||||
});
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
import { S3Client } from "bun";
|
|
||||||
|
|
||||||
interface S3Options {
|
|
||||||
accessKeyId: string
|
|
||||||
secretAccessKey: string
|
|
||||||
bucket: string
|
|
||||||
endpoint: string
|
|
||||||
}
|
|
||||||
|
|
||||||
class S3 {
|
|
||||||
private client: S3Client;
|
|
||||||
|
|
||||||
constructor(options: S3Options) {
|
|
||||||
this.client = new S3Client(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
async upload(key: string, body: File) {
|
|
||||||
return await this.client.write(key, body);
|
|
||||||
}
|
|
||||||
|
|
||||||
async get(key: string) {
|
|
||||||
return await this.client.file(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
async delete(key: string) {
|
|
||||||
return await this.client.delete(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
async presignedUrl(key: string, expiresIn: number = 3600) {
|
|
||||||
return await this.client.presign(key, { expiresIn });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const s3 = new S3({
|
|
||||||
accessKeyId: process.env.S3_ACCESS_KEY_ID!,
|
|
||||||
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY!,
|
|
||||||
bucket: process.env.S3_BUCKET!,
|
|
||||||
endpoint: process.env.S3_ENDPOINT!,
|
|
||||||
});
|
|
||||||
@@ -1,7 +1,12 @@
|
|||||||
import { auth } from "../lib/auth";
|
import { auth } from "../lib/auth";
|
||||||
import { Elysia, t } from "elysia";
|
import { Elysia, t } from "elysia";
|
||||||
|
|
||||||
const app = new Elysia().mount("/auth", auth.handler).listen(3000);
|
const app = new Elysia()
|
||||||
|
.mount("/auth", auth.handler)
|
||||||
|
.get("/health", () => "OK", {
|
||||||
|
response: t.String(),
|
||||||
|
})
|
||||||
|
.listen(3000);
|
||||||
|
|
||||||
export type App = typeof app;
|
export type App = typeof app;
|
||||||
|
|
||||||
@@ -11,5 +16,5 @@ export const PUT = app.put;
|
|||||||
export const DELETE = app.delete;
|
export const DELETE = app.delete;
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
`🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}`,
|
`🦊 Elysia is running at http://${app.server?.hostname}:${app.server?.port}`,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import Elysia from "elysia";
|
||||||
|
|
||||||
|
export const realtime = new Elysia().ws("/realtime", {
|
||||||
|
open: (ws) => {
|
||||||
|
console.log("WebSocket connection opened");
|
||||||
|
},
|
||||||
|
message: (ws, message) => {
|
||||||
|
console.log("Received message:", message);
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
export type Message = {
|
||||||
|
id: number;
|
||||||
|
roomId: string;
|
||||||
|
username: string;
|
||||||
|
content: string;
|
||||||
|
timestamp: number;
|
||||||
|
deleted: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Client -> Server
|
||||||
|
export type ClientMessage =
|
||||||
|
| { type: "join"; roomId: string }
|
||||||
|
| { type: "leave"; roomId: string }
|
||||||
|
| { type: "message"; roomId: string; m: Message }
|
||||||
|
| { type: "sync"; roomId: string };
|
||||||
|
|
||||||
|
// Server -> Client(s)
|
||||||
|
export type ServerMessage =
|
||||||
|
| { type: "joined"; username: string }
|
||||||
|
| { type: "left"; username: string }
|
||||||
|
| { type: "message"; username: string; m: Message }
|
||||||
|
| { type: "sync"; roomId: string; messages: Message[] };
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
info:
|
||||||
|
name: health
|
||||||
|
type: http
|
||||||
|
seq: 1
|
||||||
|
|
||||||
|
http:
|
||||||
|
method: GET
|
||||||
|
url: http://localhost:3000/health
|
||||||
|
auth: inherit
|
||||||
|
|
||||||
|
runtime:
|
||||||
|
assertions:
|
||||||
|
- expression: res.status
|
||||||
|
operator: eq
|
||||||
|
value: "200"
|
||||||
|
|
||||||
|
settings:
|
||||||
|
encodeUrl: true
|
||||||
|
timeout: 0
|
||||||
|
followRedirects: true
|
||||||
|
maxRedirects: 5
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
opencollection: 1.0.0
|
||||||
|
|
||||||
|
info:
|
||||||
|
name: mini-discord
|
||||||
|
bundled: false
|
||||||
|
extensions:
|
||||||
|
bruno:
|
||||||
|
ignore:
|
||||||
|
- node_modules
|
||||||
|
- .git
|
||||||
@@ -15,8 +15,7 @@ services:
|
|||||||
context: .
|
context: .
|
||||||
dockerfile: apps/server/Dockerfile
|
dockerfile: apps/server/Dockerfile
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
# Don't need to expose ports for the server since it's only accessed by the client and not directly by the user
|
||||||
- 3000
|
|
||||||
environment:
|
environment:
|
||||||
- BETTER_AUTH_URL="http://localhost:3000"
|
- BETTER_AUTH_URL="http://localhost:3000"
|
||||||
- DATABASE_URL=postgres://postgres:postgres@postgres:5432/postgres
|
- DATABASE_URL=postgres://postgres:postgres@postgres:5432/postgres
|
||||||
@@ -30,19 +29,15 @@ services:
|
|||||||
POSTGRES_USER: postgres
|
POSTGRES_USER: postgres
|
||||||
POSTGRES_PASSWORD: postgres
|
POSTGRES_PASSWORD: postgres
|
||||||
POSTGRES_DB: postgres
|
POSTGRES_DB: postgres
|
||||||
ports:
|
# Don't need to expose ports for the database since it's only accessed by the server and not directly by the user
|
||||||
- "5432:5432"
|
|
||||||
volumes:
|
volumes:
|
||||||
- postgres-data:/var/lib/postgresql/data
|
- postgres-data:/var/lib/postgresql/data
|
||||||
|
healthcheck:
|
||||||
redis:
|
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
||||||
image: redis:7
|
interval: 1m30s
|
||||||
restart: always
|
timeout: 30s
|
||||||
ports:
|
retries: 5
|
||||||
- "6379:6379"
|
start_period: 30s
|
||||||
volumes:
|
|
||||||
- redis-data:/data
|
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
postgres-data:
|
postgres-data:
|
||||||
redis-data:
|
|
||||||
Reference in New Issue
Block a user