First commit
This commit is contained in:
7
README.md
Normal file
7
README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# Project 2: XXX
|
||||
|
||||
Write the documentation of your project here. Do not include your personal
|
||||
details (e.g. name or student number).
|
||||
|
||||
Remember to include the address of the online location where your project is
|
||||
running as it is a key part of the submission.
|
||||
43
docker-compose.yml
Normal file
43
docker-compose.yml
Normal file
@@ -0,0 +1,43 @@
|
||||
version: "3.4"
|
||||
|
||||
services:
|
||||
drill-and-practice:
|
||||
build: drill-and-practice
|
||||
image: drill-and-practice
|
||||
restart: "no"
|
||||
volumes:
|
||||
- ./drill-and-practice/:/app
|
||||
ports:
|
||||
- 7777:7777
|
||||
depends_on:
|
||||
- database
|
||||
- flyway
|
||||
env_file:
|
||||
- project.env
|
||||
|
||||
database:
|
||||
container_name: database-p2-e8774b8e-c7a9-4cce-a779-3b59be02206d
|
||||
image: postgres:14.1
|
||||
restart: "no"
|
||||
env_file:
|
||||
- project.env
|
||||
|
||||
flyway:
|
||||
image: flyway/flyway:9.11.0-alpine
|
||||
depends_on:
|
||||
- database
|
||||
volumes:
|
||||
- .:/flyway/sql
|
||||
command: -connectRetries=60 -baselineOnMigrate=true migrate
|
||||
env_file:
|
||||
- project.env
|
||||
|
||||
e2e-playwright:
|
||||
entrypoint: "/bin/true" # Prevent startup on docker-compose up
|
||||
build: e2e-playwright
|
||||
image: e2e-playwright
|
||||
network_mode: host
|
||||
depends_on:
|
||||
- drill-and-practice
|
||||
volumes:
|
||||
- ./e2e-playwright/tests:/e2e-playwright/tests
|
||||
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.
|
||||
9
e2e-playwright/Dockerfile
Normal file
9
e2e-playwright/Dockerfile
Normal file
@@ -0,0 +1,9 @@
|
||||
FROM mcr.microsoft.com/playwright:v1.29.2-focal
|
||||
|
||||
COPY . /e2e-playwright
|
||||
|
||||
WORKDIR /e2e-playwright
|
||||
|
||||
RUN npm install
|
||||
|
||||
CMD [ "npx", "playwright", "test", "--reporter=list" ]
|
||||
8
e2e-playwright/package.json
Normal file
8
e2e-playwright/package.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "e2e-playwright-in-docker",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"playwright": "^1.29.2",
|
||||
"@playwright/test": "^1.29.2"
|
||||
}
|
||||
}
|
||||
19
e2e-playwright/playwright.config.js
Normal file
19
e2e-playwright/playwright.config.js
Normal file
@@ -0,0 +1,19 @@
|
||||
module.exports = {
|
||||
timeout: 10000,
|
||||
retries: 0,
|
||||
reporter: "list",
|
||||
workers: 5,
|
||||
use: {
|
||||
baseURL: "http://localhost:7777",
|
||||
headless: true,
|
||||
ignoreHTTPSErrors: true,
|
||||
},
|
||||
projects: [
|
||||
{
|
||||
name: "e2e-headless-chromium",
|
||||
use: {
|
||||
browserName: "chromium",
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
5
e2e-playwright/tests/hello-world.spec.js
Normal file
5
e2e-playwright/tests/hello-world.spec.js
Normal file
@@ -0,0 +1,5 @@
|
||||
const { test, expect } = require("@playwright/test");
|
||||
|
||||
test("Empty test", async ({ page }) => {
|
||||
|
||||
});
|
||||
41
flyway/sql/V1___initial_schema.sql
Normal file
41
flyway/sql/V1___initial_schema.sql
Normal file
@@ -0,0 +1,41 @@
|
||||
CREATE TABLE users (
|
||||
id SERIAL PRIMARY KEY,
|
||||
email VARCHAR(255) UNIQUE,
|
||||
password CHAR(60),
|
||||
admin BOOLEAN DEFAULT FALSE
|
||||
);
|
||||
|
||||
CREATE TABLE topics (
|
||||
id SERIAL PRIMARY KEY,
|
||||
user_id INTEGER REFERENCES users(id),
|
||||
name VARCHAR(255) UNIQUE
|
||||
);
|
||||
|
||||
CREATE TABLE questions (
|
||||
id SERIAL PRIMARY KEY,
|
||||
user_id INTEGER REFERENCES users(id),
|
||||
topic_id INTEGER REFERENCES topics(id),
|
||||
question_text TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE question_answer_options (
|
||||
id SERIAL PRIMARY KEY,
|
||||
question_id INTEGER REFERENCES questions(id),
|
||||
option_text TEXT NOT NULL,
|
||||
is_correct BOOLEAN DEFAULT FALSE
|
||||
);
|
||||
|
||||
CREATE TABLE question_answers (
|
||||
id SERIAL PRIMARY KEY,
|
||||
user_id INTEGER REFERENCES users(id),
|
||||
question_id INTEGER REFERENCES questions(id),
|
||||
question_answer_option_id INTEGER REFERENCES question_answer_options(id)
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX ON users((lower(email)));
|
||||
|
||||
INSERT INTO users (email, password, admin)
|
||||
VALUES ('admin@admin.com','$2a$10$IML8QCf6xA.alRbW.CG5PuvYc3Qs94vJvoTwbsSehs8s515cUMuZa', true);
|
||||
|
||||
INSERT INTO topics (user_id, name)
|
||||
VALUES ((SELECT id FROM users WHERE email = 'admin@admin.com'), 'Finnish language');
|
||||
16
project.env
Normal file
16
project.env
Normal file
@@ -0,0 +1,16 @@
|
||||
# Database configuration for PostgreSQL (running in container called "database-p2-e8774b8e-c7a9-4cce-a779-3b59be02206d")
|
||||
POSTGRES_USER=username
|
||||
POSTGRES_PASSWORD=password
|
||||
POSTGRES_DB=database
|
||||
|
||||
# Database configuration for Flyway (used for database migrations)
|
||||
FLYWAY_USER=username
|
||||
FLYWAY_PASSWORD=password
|
||||
FLYWAY_URL=jdbc:postgresql://database-p2-e8774b8e-c7a9-4cce-a779-3b59be02206d:5432/database
|
||||
|
||||
# Database configuration for Deno's PostgreSQL driver
|
||||
PGUSER=username
|
||||
PGPASSWORD=password
|
||||
PGHOST=database-p2-e8774b8e-c7a9-4cce-a779-3b59be02206d
|
||||
PGPORT=5432
|
||||
PGDATABASE=database
|
||||
Reference in New Issue
Block a user