diff options
author | Marvin Borner | 2020-07-18 21:54:58 +0200 |
---|---|---|
committer | Marvin Borner | 2020-07-18 21:54:58 +0200 |
commit | 985763e3fcb6762fa76b81c059a97648905b3761 (patch) | |
tree | e74ddab34567adcb659fcf27b2dc8b227c0c2637 | |
parent | c96473af48f650ac568a9a9203f3d6bbe74ff080 (diff) |
Started fileview
-rw-r--r-- | src/handler/fileView.ts | 6 | ||||
-rw-r--r-- | src/handler/user.ts | 5 | ||||
-rw-r--r-- | src/main.ts | 13 | ||||
-rw-r--r-- | src/public/script.js | 0 | ||||
-rw-r--r-- | src/public/style.css | 0 | ||||
-rw-r--r-- | src/util/files.ts | 7 | ||||
-rw-r--r-- | src/views/index.html | 11 |
7 files changed, 35 insertions, 7 deletions
diff --git a/src/handler/fileView.ts b/src/handler/fileView.ts new file mode 100644 index 0000000..90c7176 --- /dev/null +++ b/src/handler/fileView.ts @@ -0,0 +1,6 @@ +import type { HandlerFunc, Context } from "https://deno.land/x/abc@master/mod.ts"; +import { cleanPath } from "../util/files.ts"; + +export const handlePath: HandlerFunc = async (c: Context) => { + return await c.render("./src/views/index.html", { path: cleanPath(c.path) }); +}; diff --git a/src/handler/user.ts b/src/handler/user.ts index 28d6fbd..fe65eaa 100644 --- a/src/handler/user.ts +++ b/src/handler/user.ts @@ -2,3 +2,8 @@ import type { HandlerFunc, Context } from "https://deno.land/x/abc@master/mod.ts import db from "../db/user.ts"; export const index: HandlerFunc = async (c: Context) => c.params.name; +export const register: HandlerFunc = async (c: Context) => { + const { username, email, password } = await c.body(); + await db.createUser(email, username, password); + +} diff --git a/src/main.ts b/src/main.ts index 1772e97..94f8b33 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,14 +3,11 @@ import { Application } from "https://deno.land/x/abc@master/mod.ts"; import type { Context } from "https://deno.land/x/abc@master/mod.ts"; import { renderFile } from "https://deno.land/x/dejs/mod.ts"; import * as groups from "./groups/index.ts"; +import { handlePath } from "./handler/fileView.ts"; import DBController from "./db/DBController.ts"; -let dbc: DBController; // Ugly solution -(async () => { - dbc = new DBController(); - await dbc.init(); -})(); +(async () => await new DBController().init())(); const port = parseInt(Deno.env.get("PORT") || "8080"); const app = new Application(); @@ -21,8 +18,10 @@ app.renderer = { }, }; -app.static("/", "./src/public/"); // Manage static files - TODO: Consider serving css/js files separately -app.get("/", async (c: Context) => await c.render("./src/public/test.html", { name: "test" })); // Render index on / +app.static("/public/", "./src/public/"); // Manage static files +app.get("/", async (c: Context) => await c.render("./src/views/index.html")); // Render index on / + +app.get("/files/*", handlePath); // Load groups dynamically // deno-lint-ignore ban-ts-comment diff --git a/src/public/script.js b/src/public/script.js new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/public/script.js diff --git a/src/public/style.css b/src/public/style.css new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/public/style.css diff --git a/src/util/files.ts b/src/util/files.ts new file mode 100644 index 0000000..ec1f584 --- /dev/null +++ b/src/util/files.ts @@ -0,0 +1,7 @@ +export const cleanPath = (path: string) => { + return path + .replace("/files/", "") + .replace("../", "") // TODO: Fix relative ../ + .replace("./", "") + .replace(/([^:]\/)\/+/g, "$1"); +}; diff --git a/src/views/index.html b/src/views/index.html new file mode 100644 index 0000000..ffeb948 --- /dev/null +++ b/src/views/index.html @@ -0,0 +1,11 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="UTF-8" /> + <meta name="viewport" content="width=device-width" /> + <title>Index</title> + </head> + <body> + <% if (path) { %> <%= path %>! <% } %> + </body> +</html> |