First commit
This commit is contained in:
13
drill-and-practice/Dockerfile
Normal file
13
drill-and-practice/Dockerfile
Normal file
@@ -0,0 +1,13 @@
|
||||
FROM denoland/deno:alpine-1.29.2
|
||||
|
||||
EXPOSE 7777
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY deps.js .
|
||||
|
||||
RUN deno cache deps.js
|
||||
|
||||
COPY . .
|
||||
|
||||
CMD [ "run", "--unstable", "--watch", "--allow-net", "--allow-read", "--allow-env", "--no-check", "app-launch.js" ]
|
||||
3
drill-and-practice/app-launch.js
Normal file
3
drill-and-practice/app-launch.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import { app } from "./app.js";
|
||||
|
||||
app.listen({ port: 7777 });
|
||||
14
drill-and-practice/app.js
Normal file
14
drill-and-practice/app.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import { Application } from "./deps.js";
|
||||
import { errorMiddleware } from "./middlewares/errorMiddleware.js";
|
||||
import { renderMiddleware } from "./middlewares/renderMiddleware.js";
|
||||
import { serveStaticMiddleware } from "./middlewares/serveStaticMiddleware.js";
|
||||
import { router } from "./routes/routes.js";
|
||||
|
||||
const app = new Application();
|
||||
|
||||
app.use(errorMiddleware);
|
||||
app.use(serveStaticMiddleware);
|
||||
app.use(renderMiddleware);
|
||||
app.use(router.routes());
|
||||
|
||||
export { app };
|
||||
1
drill-and-practice/config/readme.txt
Normal file
1
drill-and-practice/config/readme.txt
Normal file
@@ -0,0 +1 @@
|
||||
You could add project configuration files here.
|
||||
10
drill-and-practice/database/database.js
Normal file
10
drill-and-practice/database/database.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import { postgres } from "../deps.js";
|
||||
|
||||
let sql;
|
||||
if (Deno.env.get("DATABASE_URL")) {
|
||||
sql = postgres(Deno.env.get("DATABASE_URL"));
|
||||
} else {
|
||||
sql = postgres({});
|
||||
}
|
||||
|
||||
export { sql };
|
||||
11
drill-and-practice/deps.js
Normal file
11
drill-and-practice/deps.js
Normal file
@@ -0,0 +1,11 @@
|
||||
export { configure, renderFile } from "https://deno.land/x/eta@v2.0.0/mod.ts";
|
||||
export {
|
||||
Application,
|
||||
Router,
|
||||
send,
|
||||
} from "https://deno.land/x/oak@v11.1.0/mod.ts";
|
||||
import postgres from "https://deno.land/x/postgresjs@v3.3.3/mod.js";
|
||||
export { postgres };
|
||||
export { Session } from "https://deno.land/x/oak_sessions@v4.0.5/mod.ts";
|
||||
export * as bcrypt from "https://deno.land/x/bcrypt@v0.4.1/mod.ts";
|
||||
export * as validasaur from "https://deno.land/x/validasaur@v0.15.0/mod.ts";
|
||||
9
drill-and-practice/middlewares/errorMiddleware.js
Normal file
9
drill-and-practice/middlewares/errorMiddleware.js
Normal file
@@ -0,0 +1,9 @@
|
||||
const errorMiddleware = async (context, next) => {
|
||||
try {
|
||||
await next();
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
};
|
||||
|
||||
export { errorMiddleware };
|
||||
16
drill-and-practice/middlewares/renderMiddleware.js
Normal file
16
drill-and-practice/middlewares/renderMiddleware.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import { configure, renderFile } from "../deps.js";
|
||||
|
||||
const renderMiddleware = async (context, next) => {
|
||||
configure({
|
||||
views: `${Deno.cwd()}/views/`,
|
||||
});
|
||||
|
||||
context.render = async (file, data) => {
|
||||
context.response.headers.set("Content-Type", "text/html; charset=utf-8");
|
||||
context.response.body = await renderFile(file, data);
|
||||
};
|
||||
|
||||
await next();
|
||||
};
|
||||
|
||||
export { renderMiddleware };
|
||||
15
drill-and-practice/middlewares/serveStaticMiddleware.js
Normal file
15
drill-and-practice/middlewares/serveStaticMiddleware.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import { send } from "../deps.js";
|
||||
|
||||
const serveStaticMiddleware = async (context, next) => {
|
||||
if (context.request.url.pathname.startsWith("/static")) {
|
||||
const path = context.request.url.pathname.substring(7);
|
||||
|
||||
await send(context, path, {
|
||||
root: `${Deno.cwd()}/static`,
|
||||
});
|
||||
} else {
|
||||
await next();
|
||||
}
|
||||
};
|
||||
|
||||
export { serveStaticMiddleware };
|
||||
1
drill-and-practice/routes/apis/readme.txt
Normal file
1
drill-and-practice/routes/apis/readme.txt
Normal file
@@ -0,0 +1 @@
|
||||
You could add api-related endpoints here.
|
||||
5
drill-and-practice/routes/controllers/mainController.js
Normal file
5
drill-and-practice/routes/controllers/mainController.js
Normal file
@@ -0,0 +1,5 @@
|
||||
const showMain = ({ render }) => {
|
||||
render("main.eta");
|
||||
};
|
||||
|
||||
export { showMain };
|
||||
8
drill-and-practice/routes/routes.js
Normal file
8
drill-and-practice/routes/routes.js
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Router } from "../deps.js";
|
||||
import * as mainController from "./controllers/mainController.js";
|
||||
|
||||
const router = new Router();
|
||||
|
||||
router.get("/", mainController.showMain);
|
||||
|
||||
export { router };
|
||||
1
drill-and-practice/services/readme.txt
Normal file
1
drill-and-practice/services/readme.txt
Normal file
@@ -0,0 +1 @@
|
||||
You could add services here
|
||||
1
drill-and-practice/static/readme.txt
Normal file
1
drill-and-practice/static/readme.txt
Normal file
@@ -0,0 +1 @@
|
||||
You could add static content here. Note that you cannot currently submit binary data.
|
||||
1
drill-and-practice/tests/readme.txt
Normal file
1
drill-and-practice/tests/readme.txt
Normal file
@@ -0,0 +1 @@
|
||||
Implement tests here.
|
||||
1
drill-and-practice/views/layouts/layout.eta
Normal file
1
drill-and-practice/views/layouts/layout.eta
Normal file
@@ -0,0 +1 @@
|
||||
<%~ it.body %>
|
||||
3
drill-and-practice/views/main.eta
Normal file
3
drill-and-practice/views/main.eta
Normal file
@@ -0,0 +1,3 @@
|
||||
<% layout("./layouts/layout.eta") %>
|
||||
|
||||
<h1>Hello world!</h1>
|
||||
1
drill-and-practice/views/partials/readme.txt
Normal file
1
drill-and-practice/views/partials/readme.txt
Normal file
@@ -0,0 +1 @@
|
||||
Add any necessary partials here.
|
||||
Reference in New Issue
Block a user