aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2020-07-18 21:54:58 +0200
committerMarvin Borner2020-07-18 21:54:58 +0200
commit985763e3fcb6762fa76b81c059a97648905b3761 (patch)
treee74ddab34567adcb659fcf27b2dc8b227c0c2637
parentc96473af48f650ac568a9a9203f3d6bbe74ff080 (diff)
Started fileview
-rw-r--r--src/handler/fileView.ts6
-rw-r--r--src/handler/user.ts5
-rw-r--r--src/main.ts13
-rw-r--r--src/public/script.js0
-rw-r--r--src/public/style.css0
-rw-r--r--src/util/files.ts7
-rw-r--r--src/views/index.html11
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>