Prepare for deploy
This commit is contained in:
@@ -5,7 +5,9 @@
|
||||
"packages/*"
|
||||
],
|
||||
"scripts": {
|
||||
"dev": "bun run --filter '*' dev"
|
||||
"build": "bun run --filter 'fe' build",
|
||||
"dev": "bun run --filter 'fe' dev & bun run --filter 'be' dev",
|
||||
"start": "bun run --filter 'fe' start & bun run --filter 'be' start"
|
||||
},
|
||||
"devDependencies": {
|
||||
"bun-types": "latest",
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
"name": "be",
|
||||
"version": "0.0.0",
|
||||
"scripts": {
|
||||
"dev": "bun run --watch src/index.ts"
|
||||
"dev": "bun run --watch src/index.ts",
|
||||
"start": "bun run src/index.ts"
|
||||
},
|
||||
"exports": {
|
||||
"./websocket/types": "./src/websocket/types.ts"
|
||||
@@ -10,5 +11,8 @@
|
||||
"dependencies": {
|
||||
"@elysiajs/jwt": "^1.2.0",
|
||||
"elysia": "^1.2.25"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bun": "^1.2.10"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,12 @@
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { db } from '.';
|
||||
|
||||
type Item = {
|
||||
id: string;
|
||||
listId: string;
|
||||
label: string;
|
||||
checked: boolean;
|
||||
};
|
||||
|
||||
type ItemWithoutId = {
|
||||
listId: string;
|
||||
label?: string;
|
||||
checked?: boolean;
|
||||
};
|
||||
|
||||
type List = {
|
||||
id: string;
|
||||
title: string;
|
||||
items: Item[];
|
||||
createdAt: Date;
|
||||
};
|
||||
|
||||
type ListWithoutId = {
|
||||
title?: string;
|
||||
createdAt?: Date;
|
||||
|
||||
@@ -76,7 +76,7 @@ const app = new Elysia()
|
||||
deleteItemBody,
|
||||
]),
|
||||
open(ws) {
|
||||
const result = open({ ws });
|
||||
const result = open({ data: ws.data });
|
||||
|
||||
if ('action' in result) {
|
||||
ws.subscribe('todo-updates');
|
||||
@@ -90,7 +90,7 @@ const app = new Elysia()
|
||||
|
||||
switch (message.action) {
|
||||
case 'login': {
|
||||
login({ ws, message, validTokens }).then(result => ws.send(JSON.stringify(result)));
|
||||
login({ data: ws.data, message, validTokens }).then(result => ws.send(JSON.stringify(result)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -100,7 +100,7 @@ const app = new Elysia()
|
||||
|
||||
switch (message.action) {
|
||||
case 'logout': {
|
||||
ws.send(JSON.stringify(logout({ ws, message, validTokens })));
|
||||
ws.send(JSON.stringify(logout({ data: ws.data, message, validTokens })));
|
||||
break;
|
||||
}
|
||||
case 'create-list': {
|
||||
@@ -143,3 +143,5 @@ const app = new Elysia()
|
||||
});
|
||||
|
||||
app.listen(process.env.PORT ?? 3000);
|
||||
|
||||
console.log(`BE running on port ${process.env.PORT}`);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { t, type Static } from 'elysia';
|
||||
import { userDTO } from '../db/user-dto';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import type { ElysiaWS } from 'elysia/dist/ws';
|
||||
|
||||
export const loginBody = t.Object({
|
||||
action: t.Literal('login'),
|
||||
@@ -12,12 +11,12 @@ export const loginBody = t.Object({
|
||||
export type LoginBody = Static<typeof loginBody>;
|
||||
|
||||
type Args = {
|
||||
ws: ElysiaWS<{ jwt_auth: { sign: (payload: any) => Promise<string> } }>;
|
||||
data: { jwt_auth: { sign: (payload: any) => Promise<string> } };
|
||||
message: LoginBody;
|
||||
validTokens: Set<string>;
|
||||
};
|
||||
|
||||
export const login = async ({ ws, message, validTokens }: Args) => {
|
||||
export const login = async ({ data, message, validTokens }: Args) => {
|
||||
const foundUser = userDTO.findUserByEmail(message.email);
|
||||
|
||||
if (!foundUser) {
|
||||
@@ -30,7 +29,7 @@ export const login = async ({ ws, message, validTokens }: Args) => {
|
||||
return { error: 'password is incorrect' };
|
||||
}
|
||||
|
||||
const token = await ws.data.jwt_auth.sign({
|
||||
const token = await data.jwt_auth.sign({
|
||||
id: foundUser.id,
|
||||
sessionId: randomUUID(),
|
||||
});
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { t, type Static } from 'elysia';
|
||||
import type { ElysiaWS } from 'elysia/dist/ws';
|
||||
|
||||
export const logoutBody = t.Object({
|
||||
action: t.Literal('logout'),
|
||||
@@ -8,14 +7,14 @@ export const logoutBody = t.Object({
|
||||
export type LogoutBody = Static<typeof logoutBody>;
|
||||
|
||||
type Args = {
|
||||
ws: ElysiaWS<{ token?: string }>;
|
||||
data: { token?: string };
|
||||
message: LogoutBody;
|
||||
validTokens: Set<string>;
|
||||
};
|
||||
|
||||
export const logout = ({ ws, validTokens }: Args) => {
|
||||
if (ws.data.token) {
|
||||
validTokens.delete(ws.data.token);
|
||||
export const logout = ({ data, validTokens }: Args) => {
|
||||
if (data.token) {
|
||||
validTokens.delete(data.token);
|
||||
}
|
||||
|
||||
return { status: 'unauthorized' as const };
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import type { ElysiaWS } from 'elysia/dist/ws';
|
||||
import { dataDTO } from '../db/data-dto';
|
||||
import type { JWTPayloadSpec } from '@elysiajs/jwt';
|
||||
|
||||
type Args = {
|
||||
ws: ElysiaWS<{ token?: string; user: false | (Record<string, string | number> & JWTPayloadSpec) | null }>;
|
||||
data: { token?: string; user: false | (Record<string, string | number> & JWTPayloadSpec) | null };
|
||||
};
|
||||
|
||||
export const open = ({ ws }: Args) => {
|
||||
if (!ws.data.user || !ws.data.token) {
|
||||
export const open = ({ data }: Args) => {
|
||||
if (!data.user || !data.token) {
|
||||
return { action: 'status' as const, status: 'unauthorized' as const };
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#PUBLIC_BOX_DRAWING_CHARS=─│┌┐└┘├┤
|
||||
PUBLIC_BOX_DRAWING_CHARS=-|++++++
|
||||
PUBLIC_WS_URL=wss://echo.websocket.org
|
||||
HOST=example.org
|
||||
PORT=5173
|
||||
@@ -6,7 +6,8 @@
|
||||
"dev": "vite",
|
||||
"build": "tsc -b && vite build",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview"
|
||||
"preview": "vite preview",
|
||||
"start": "vite preview --host"
|
||||
},
|
||||
"dependencies": {
|
||||
"@formkit/auto-animate": "^0.8.2",
|
||||
|
||||
@@ -68,7 +68,7 @@ export const WsProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
|
||||
const connectWebSocket = useCallback(() => {
|
||||
dispatch({ status: 'connecting' });
|
||||
const ws = new WebSocket(import.meta.env.PUBLIC_WS_URL);
|
||||
const ws = new WebSocket(import.meta.env.PUBLIC_WS_URL!);
|
||||
|
||||
if (wsRef.current) {
|
||||
wsRef.current.close();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const boxDrawingChars = import.meta.env.PUBLIC_BOX_DRAWING_CHARS;
|
||||
const boxDrawingChars = import.meta.env.PUBLIC_BOX_DRAWING_CHARS!;
|
||||
|
||||
export const bdcHorizontal = boxDrawingChars[0];
|
||||
export const bdcVertical = boxDrawingChars[1];
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import { defineConfig, loadEnv } from 'vite';
|
||||
import react from '@vitejs/plugin-react-swc';
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
envPrefix: 'PUBLIC_',
|
||||
plugins: [react()],
|
||||
server: {
|
||||
allowedHosts: ['todo-test.bate-estacas.xyz', 'localhost', '0.0.0.0'],
|
||||
},
|
||||
});
|
||||
export default ({ mode }: { mode: string }) => {
|
||||
const env = loadEnv(mode, process.cwd(), '');
|
||||
|
||||
return defineConfig({
|
||||
envPrefix: 'PUBLIC_',
|
||||
plugins: [react()],
|
||||
server: {
|
||||
allowedHosts: [env.HOST!],
|
||||
port: Number(env.PORT!),
|
||||
},
|
||||
preview: {
|
||||
allowedHosts: [env.HOST!],
|
||||
port: Number(env.PORT!),
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user