diff --git a/.idea/.gitignore b/.idea/.gitignore
deleted file mode 100644
index 73f69e0..0000000
--- a/.idea/.gitignore
+++ /dev/null
@@ -1,8 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
-# Datasource local storage ignored files
-/dataSources/
-/dataSources.local.xml
-# Editor-based HTTP Client requests
-/httpRequests/
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
deleted file mode 100644
index a55e7a1..0000000
--- a/.idea/codeStyles/codeStyleConfig.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/hello-server.iml b/.idea/hello-server.iml
index 8dc09e5..d0876a7 100644
--- a/.idea/hello-server.iml
+++ b/.idea/hello-server.iml
@@ -5,7 +5,4 @@
-
-
-
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
index 648db79..3d27f1f 100644
--- a/.idea/inspectionProfiles/Project_Default.xml
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -2,6 +2,7 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/watcherTasks.xml b/.idea/watcherTasks.xml
index 87269d2..c53bf7f 100644
--- a/.idea/watcherTasks.xml
+++ b/.idea/watcherTasks.xml
@@ -7,7 +7,7 @@
-
+
@@ -15,7 +15,7 @@
-
+
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..1f8031c
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,130 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ test
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1629302841743
+
+
+ 1629302841743
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.vscode/configurationCache.log b/.vscode/configurationCache.log
new file mode 100644
index 0000000..df66325
--- /dev/null
+++ b/.vscode/configurationCache.log
@@ -0,0 +1 @@
+{"buildTargets":["cli","lint","run","tests"],"launchTargets":[],"customConfigurationProvider":{"workspaceBrowse":{"browsePath":[],"compilerArgs":[]},"fileIndex":[]}}
\ No newline at end of file
diff --git a/.vscode/dryrun.log b/.vscode/dryrun.log
new file mode 100644
index 0000000..a447ce1
--- /dev/null
+++ b/.vscode/dryrun.log
@@ -0,0 +1,5 @@
+make -f "/Users/ruidy/Dev/_Perso/deno/hello-server/Makefile" --dry-run --always-make --keep-going --print-directory
+make: Entering directory `/Users/ruidy/Dev/_Perso/deno/hello-server'
+deno run cli.ts
+make: Leaving directory `/Users/ruidy/Dev/_Perso/deno/hello-server'
+
diff --git a/.vscode/settings.json b/.vscode/settings.json
index f8d9cfd..23631e6 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,14 +1,19 @@
{
- "deno.enable": true,
- "deno.unstable": true,
- "deno.lint": true,
- "deno.import_intellisense_origins": {
- "https://deno.land": true
- },
- "[typescript]": {
- "editor.defaultFormatter": "denoland.vscode-deno"
- },
- "[typescriptreact]": {
- "editor.defaultFormatter": "denoland.vscode-deno"
- }
+ "deno.enable": true,
+ "deno.unstable": true,
+ "deno.lint": true,
+ "[typescript]": {
+ "editor.defaultFormatter": "denoland.vscode-deno"
+ },
+ "[typescriptreact]": {
+ "editor.defaultFormatter": "denoland.vscode-deno"
+ },
+ "files.eol": "\n",
+ "files.trimTrailingWhitespace": true,
+ "files.exclude": {
+ "**/.git": true,
+ "**/.DS_Store": true,
+ "**/Thumbs.db": true,
+ "**/.aleph": true
+ }
}
diff --git a/.vscode/targets.log b/.vscode/targets.log
new file mode 100644
index 0000000..c20db93
--- /dev/null
+++ b/.vscode/targets.log
@@ -0,0 +1,290 @@
+make all -f "/Users/ruidy/Dev/_Perso/deno/hello-server/Makefile" --print-data-base --no-builtin-variables --no-builtin-rules --question
+# GNU Make 3.81
+# Copyright (C) 2006 Free Software Foundation, Inc.
+# This is free software; see the source for copying conditions.
+# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+# This program built for i386-apple-darwin11.3.0
+
+# Make data base, printed on Sun Jun 27 15:52:43 2021
+
+# Variables
+
+# automatic
+ {
- const router = new Router();
-
- router.get("/", (ctx: RouterContext) => {
- ctx.response.body = htmlBody(sayRandomHello());
- }).get("/:id", (ctx: RouterContext) => {
- try {
- const value = ctx.params.id;
- if (value) {
- const id = new ID(parseInt(value, 10));
- ctx.response.body = htmlBody(sayHello(id));
- }
- } catch (error) {
- console.error(error);
- ctx.response.body = error.message;
- }
- });
-
- const app = new Application();
-
- app.use(router.routes());
-
- app.addEventListener(
- "listen",
- () => console.log(`Server listening on http://localhost:${port}/`),
- );
- return app;
-};
-
-const app = getApplication({ port });
-
-await app.listen({ port });
-console.log(`Finished`);
diff --git a/cli.ts b/src/cli.ts
similarity index 98%
rename from cli.ts
rename to src/cli.ts
index 7f2ff94..518651a 100644
--- a/cli.ts
+++ b/src/cli.ts
@@ -1,5 +1,5 @@
import { readLines } from "./deps.ts";
-import { ID, sayHello, sayRandomHello, ValidationError } from "./src/index.ts";
+import { ID, sayHello, sayRandomHello, ValidationError } from "./mod.ts";
const start = async () => {
console.log("Hello, World! (International version)\n");
diff --git a/deps.ts b/src/deps.ts
similarity index 64%
rename from deps.ts
rename to src/deps.ts
index 8feda56..268af89 100644
--- a/deps.ts
+++ b/src/deps.ts
@@ -6,4 +6,8 @@ export {
} from "https://deno.land/std@0.87.0/testing/asserts.ts";
export { readLines } from "https://deno.land/std@0.87.0/io/bufio.ts";
export { Application, Router } from "https://deno.land/x/oak/mod.ts";
-export type { RouterContext } from "https://deno.land/x/oak/mod.ts";
+export type {
+ RouteParams,
+ RouterContext,
+} from "https://deno.land/x/oak/mod.ts";
+export { Random } from "https://deno.land/x/random/Random.js";
diff --git a/src/main.ts b/src/main.ts
new file mode 100644
index 0000000..c5f4cb9
--- /dev/null
+++ b/src/main.ts
@@ -0,0 +1,9 @@
+import { router } from "./routes.ts";
+import { getApplication } from "./server.ts";
+
+const port = 8000;
+
+const app = getApplication({ port, router });
+
+await app.listen({ port });
+console.log(`Finished`);
diff --git a/src/index.ts b/src/mod.ts
similarity index 100%
rename from src/index.ts
rename to src/mod.ts
diff --git a/src/repositories/locales.test.ts b/src/repositories/locales.test.ts
index 33c0be1..890afca 100644
--- a/src/repositories/locales.test.ts
+++ b/src/repositories/locales.test.ts
@@ -1,4 +1,4 @@
-import { assertEquals } from "../../deps.ts";
+import { assertEquals } from "../deps.ts";
import { getLocaleById, Locale } from "./locales.ts";
Deno.test("Get locale by id", () => {
diff --git a/src/routes.ts b/src/routes.ts
new file mode 100644
index 0000000..87e4054
--- /dev/null
+++ b/src/routes.ts
@@ -0,0 +1,24 @@
+import { Router, RouterContext } from "./deps.ts";
+import { ID, sayHello, sayRandomHello } from "./mod.ts";
+import { htmlBody } from "./view.ts";
+
+export const router = new Router();
+
+router.get("/", (ctx: RouterContext) => {
+ ctx.response.body = htmlBody(sayRandomHello());
+});
+
+router.get<
+ Record
+>("/:id", (ctx: RouterContext) => {
+ try {
+ const value = ctx.params.id;
+ if (value && value !== "favicon.ico") {
+ const id = new ID(parseInt(value, 10));
+ ctx.response.body = htmlBody(sayHello(id));
+ }
+ } catch (error) {
+ console.error(error);
+ ctx.response.body = error.message;
+ }
+});
diff --git a/src/server.ts b/src/server.ts
new file mode 100644
index 0000000..072740f
--- /dev/null
+++ b/src/server.ts
@@ -0,0 +1,15 @@
+import { Application, Router } from "./deps.ts";
+
+type AppOpts = { port: number; router: Router };
+
+export const getApplication = ({ port, router }: AppOpts): Application => {
+ const app = new Application();
+
+ app.use(router.routes());
+
+ app.addEventListener(
+ "listen",
+ () => console.log(`Server listening on http://localhost:${port}/`),
+ );
+ return app;
+};
diff --git a/src/types/id.test.ts b/src/types/id.test.ts
index 5623ed9..3377a82 100644
--- a/src/types/id.test.ts
+++ b/src/types/id.test.ts
@@ -1,4 +1,4 @@
-import { assertThrows } from "../../deps.ts";
+import { assert, assertThrows, Random } from "../deps.ts";
import { ValidationError } from "../errors/exceptions.ts";
import { ID } from "./id.ts";
@@ -9,3 +9,9 @@ Deno.test("ID validation fails for non strictly positive values", () => {
Deno.test("Hello fails for too large values", () => {
assertThrows(() => new ID(666), ValidationError, `Invalid index: 666`);
});
+
+Deno.test("ID is valid", () => {
+ const value = new Random().int(1, 77);
+ const id = new ID(value);
+ assert(id);
+});
diff --git a/src/usecases/hello.test.ts b/src/usecases/hello.test.ts
index 99d4962..5316e99 100644
--- a/src/usecases/hello.test.ts
+++ b/src/usecases/hello.test.ts
@@ -1,4 +1,4 @@
-import { assertEquals, assertStrictEquals } from "../../deps.ts";
+import { assertEquals, assertStrictEquals } from "../deps.ts";
import { ID } from "../types/id.ts";
import { HelloResponse, sayHello, sayRandomHello } from "./hello.ts";
diff --git a/view.ts b/src/view.ts
similarity index 96%
rename from view.ts
rename to src/view.ts
index 87bd43b..f7547ec 100644
--- a/view.ts
+++ b/src/view.ts
@@ -1,4 +1,4 @@
-import { Locale } from "./src/repositories/locales.ts";
+import { Locale } from "./repositories/locales.ts";
export const htmlBody = ({ locale: language, message: hello }: Locale) =>
`