diff --git a/.gitignore b/.gitignore index ff2fab0..76c7240 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,8 @@ **/yarn-error.log **/.history -/backend/cwd/ +/backend/keys +/backend/images /backend/pacakage.json /frontend/dist @@ -13,13 +14,13 @@ /frontend/out-tsc /frontend/bazel-out -/frontent/.angular/cache -/frontent/**/.sass-cache/ -/frontent/connect.lock -/frontent/coverage -/frontent/libpeerconnection.log -/frontent/**/testem.log -/frontent/typings +/frontend/.angular/cache +/frontend/**/.sass-cache/ +/frontend/connect.lock +/frontend/coverage +/frontend/libpeerconnection.log +/frontend/**/testem.log +/frontend/typings -/frontend/**/.DS_Store -/frontend/**/Thumbs.db \ No newline at end of file +frontend/**/.DS_Store +frontend/**/Thumbs.db \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index 24b8237..95f171d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,7 +8,7 @@ "name": "Launch Backend", "type": "pwa-node", "request": "launch", - "program": "${workspaceFolder}/src/index.ts", + "program": "${workspaceFolder}/main.ts", "cwd": "${workspaceFolder}/cwd", "runtimeExecutable": "deno", "runtimeArgs": [ diff --git a/README.md b/README.md index 22fba4b..788ea23 100644 --- a/README.md +++ b/README.md @@ -12,10 +12,37 @@ Created by TopchetoEU This is exactly what the title sells it for - it's an imgur clone (but kinda worse). -## How to use? +## Running the code -Currently, we only have a backend, which can be easily run via the command (in the main directory): +### Development + +Start the backend with: ```sh +# Executed in the backend folder $ deno run -A src/index.ts ``` + +And the frontend with: + +```sh +# Executed in the frontend folder +$ ng serve +``` + +### Production + +First, build the frontend: + +```sh +# Executed in the frontend folder +$ ng build +``` + +Then, copy the contents of backend/static. Finally start the backend: + +```sh +# Executed in the backend folder +$ deno run --allow-read --allow-write --allow-net main.ts +``` + diff --git a/backend/src/AppDatabase.ts b/backend/AppDatabase.ts similarity index 100% rename from backend/src/AppDatabase.ts rename to backend/AppDatabase.ts diff --git a/backend/src/index.ts b/backend/clonegur.ts similarity index 90% rename from backend/src/index.ts rename to backend/clonegur.ts index 2c55d88..f0d6be0 100644 --- a/backend/src/index.ts +++ b/backend/clonegur.ts @@ -21,4 +21,3 @@ export default async function clonegur() { return new RootRouter(salt, new AppDatabase(db)); } -(await clonegur()).attach(Deno.listen({ port: 4000, hostname: 'localhost' })); diff --git a/backend/main.ts b/backend/main.ts new file mode 100644 index 0000000..6496e2e --- /dev/null +++ b/backend/main.ts @@ -0,0 +1,5 @@ +import clonegur from "./clonegur.ts"; + +const app = await clonegur(); +const server = Deno.listen({ port: 4000, hostname: 'localhost' }); +app.attach(server); diff --git a/backend/src/models/Image.ts b/backend/models/Image.ts similarity index 100% rename from backend/src/models/Image.ts rename to backend/models/Image.ts diff --git a/backend/src/models/User.ts b/backend/models/User.ts similarity index 100% rename from backend/src/models/User.ts rename to backend/models/User.ts diff --git a/backend/src/routers/AppRouter.ts b/backend/routers/AppRouter.ts similarity index 100% rename from backend/src/routers/AppRouter.ts rename to backend/routers/AppRouter.ts diff --git a/backend/src/routers/ImageRouter.ts b/backend/routers/ImageRouter.ts similarity index 100% rename from backend/src/routers/ImageRouter.ts rename to backend/routers/ImageRouter.ts diff --git a/backend/src/routers/RootRouter.ts b/backend/routers/RootRouter.ts similarity index 100% rename from backend/src/routers/RootRouter.ts rename to backend/routers/RootRouter.ts diff --git a/backend/src/routers/UserRouter.ts b/backend/routers/UserRouter.ts similarity index 100% rename from backend/src/routers/UserRouter.ts rename to backend/routers/UserRouter.ts diff --git a/backend/src/server/HttpError.ts b/backend/server/HttpError.ts similarity index 100% rename from backend/src/server/HttpError.ts rename to backend/server/HttpError.ts diff --git a/backend/src/server/RestRequest.ts b/backend/server/RestRequest.ts similarity index 100% rename from backend/src/server/RestRequest.ts rename to backend/server/RestRequest.ts diff --git a/backend/src/server/RestResponse.ts b/backend/server/RestResponse.ts similarity index 100% rename from backend/src/server/RestResponse.ts rename to backend/server/RestResponse.ts diff --git a/backend/src/server/Router.ts b/backend/server/Router.ts similarity index 98% rename from backend/src/server/Router.ts rename to backend/server/Router.ts index fd8e778..7b02b8b 100644 --- a/backend/src/server/Router.ts +++ b/backend/server/Router.ts @@ -97,7 +97,7 @@ export default class Router { } } - public async attach(server: Deno.Listener) { + public async attach(server: AsyncIterable) { for await (const conn of server) { for await (const req of Deno.serveHttp(conn)) { const r = await this.handle(RestRequest.fromMessage(req)); diff --git a/backend/src/server/decorators.ts b/backend/server/decorators.ts similarity index 100% rename from backend/src/server/decorators.ts rename to backend/server/decorators.ts diff --git a/backend/src/server/decorators/auth.ts b/backend/server/decorators/auth.ts similarity index 100% rename from backend/src/server/decorators/auth.ts rename to backend/server/decorators/auth.ts diff --git a/backend/src/server/decorators/body.ts b/backend/server/decorators/body.ts similarity index 100% rename from backend/src/server/decorators/body.ts rename to backend/server/decorators/body.ts diff --git a/backend/src/server/decorators/headers.ts b/backend/server/decorators/headers.ts similarity index 100% rename from backend/src/server/decorators/headers.ts rename to backend/server/decorators/headers.ts diff --git a/backend/src/server/decorators/jwt.ts b/backend/server/decorators/jwt.ts similarity index 100% rename from backend/src/server/decorators/jwt.ts rename to backend/server/decorators/jwt.ts diff --git a/backend/src/server/decorators/page.ts b/backend/server/decorators/page.ts similarity index 100% rename from backend/src/server/decorators/page.ts rename to backend/server/decorators/page.ts diff --git a/backend/src/server/decorators/rest.ts b/backend/server/decorators/rest.ts similarity index 100% rename from backend/src/server/decorators/rest.ts rename to backend/server/decorators/rest.ts diff --git a/backend/src/server/decorators/route.ts b/backend/server/decorators/route.ts similarity index 100% rename from backend/src/server/decorators/route.ts rename to backend/server/decorators/route.ts diff --git a/backend/src/server/decorators/schema.ts b/backend/server/decorators/schema.ts similarity index 100% rename from backend/src/server/decorators/schema.ts rename to backend/server/decorators/schema.ts diff --git a/backend/src/server/serialize.ts b/backend/server/serialize.ts similarity index 100% rename from backend/src/server/serialize.ts rename to backend/server/serialize.ts diff --git a/backend/server/staticHandler.ts b/backend/server/staticHandler.ts new file mode 100644 index 0000000..1b31ae8 --- /dev/null +++ b/backend/server/staticHandler.ts @@ -0,0 +1,19 @@ +import RestResponse from "./RestResponse.ts"; +import { Handler } from "./Router.ts"; + +export default function staticHandler(path: string): Handler { + return { + async handle(req) { + try { + const stream = await Deno.open(`${req.url}/${path}`); + const res: Uint8Array[] = []; + for await (const bit of stream.readable) res.push(bit); + stream.close(); + return new RestResponse().body(new Blob(res).stream()); + } + catch { + return undefined; + } + } + }; +} \ No newline at end of file diff --git a/backend/src/utils/JWT.ts b/backend/utils/JWT.ts similarity index 100% rename from backend/src/utils/JWT.ts rename to backend/utils/JWT.ts diff --git a/backend/src/utils/utils.ts b/backend/utils/utils.ts similarity index 100% rename from backend/src/utils/utils.ts rename to backend/utils/utils.ts