diff --git a/api/.dockerignore b/api/.dockerignore new file mode 100644 index 0000000000000000000000000000000000000000..b512c09d476623ff4bf8d0d63c29b784925dbdf8 --- /dev/null +++ b/api/.dockerignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/api/Dockerfile b/api/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..ea1f9c9de9c7b797caf7c3d80f827ed87f5fc857 --- /dev/null +++ b/api/Dockerfile @@ -0,0 +1,13 @@ +FROM node:16 + +WORKDIR /usr/app + +COPY package*.json ./ + +RUN npm install + +COPY . . + +ENV PORT=8000 + +EXPOSE 8000 \ No newline at end of file diff --git a/api/index.js b/api/index.js index c3d3d0c38be0544f92b44e1073b4e128eb640e20..55dfd46b43293c9b4e2adef5e700808eb75217bd 100644 --- a/api/index.js +++ b/api/index.js @@ -21,7 +21,7 @@ const options = { origin: "*" }; const app = (0, express_1.default)(); -const port = process.env.API_PORT; +const port = process.env.API_PORT || 8000; app.use((0, cors_1.default)(options)); app.use(express_1.default.json()); app.use(express_1.default.urlencoded()); diff --git a/api/index.ts b/api/index.ts index 7e5de8132918d0309e207e270b9760ff1611488f..c4efa31483bb0dabd7fc06112e1ddb426f204e06 100644 --- a/api/index.ts +++ b/api/index.ts @@ -20,7 +20,7 @@ const options: cors.CorsOptions = { }; const app = express(); -const port = process.env.API_PORT; +const port = process.env.API_PORT || 8000; app.use(cors(options)); app.use(express.json()); diff --git a/docker-compose.yml b/docker-compose.yml index 753e8552f36ef60a22c8af582820fb7018177c58..99ff1f418fb4d8464f6ee6e88ef1b630937f485e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,6 +27,16 @@ services: # command: npm run dev # volumes: # - ./frontend:/usr/app/ - # - ./frontend/node_modules:/usr/app/node_modules # ports: # - "5173:5173" + # api: + # build: ./api + # command: npm run dev + # volumes: + # - ./api:/usr/app/ + # ports: + # - "8000:8000" + # env_file: ./.env + # depends_on: + # - database + # restart: on-failure diff --git a/frontend-client/index.html b/frontend-client/index.html new file mode 100644 index 0000000000000000000000000000000000000000..0bbd06f264dfd01aee7943ef012aafe4cae271cb --- /dev/null +++ b/frontend-client/index.html @@ -0,0 +1,136 @@ +<!DOCTYPE html> +<html lang="fr"> +<head> + <meta charset="UTF-8"> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>Document</title> + <style> + html, body { + margin: 0; + padding: 0; + font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; + } + + #container { + margin: auto; + width: 90%; + max-width: 800px; + } + + h1 { + text-align: center; + } + + #classment { + margin-top: 50px; + width: 100%; + } + + #classment tr td { + text-align: center; + } + + form { + text-align: center; + } + + table, + tr, + td{ + border: 1px solid black; + } + + tr:nth-child(even){background-color: #f2f2f2;} + tr:hover {background-color: #ddd;} + + table { + border-collapse: collapse; + width: 100%; + margin-top: 15px; + margin-bottom: 15px; + } + + th { + background-color: #061b41; + color: white; + font-size: 1.2em; + } + + </style> +</head> +<body> + <div id="container"> + <h1>Bol d'or Mirabaud - classement</h1> + <form action="#"> + <select name="edition" id="edition"> + <option value="">2022</option> + <option value="">2023</option> + <option value="">2024</option> + <option value="">2025</option> + </select> + <label for="refresh">Vitesse de rafraichissement (ms)</label> + <input type="number" for="refresh" min="500" value="1000"> + <button id="btn_display_classment">Affiche les résultats</button> + </form> + + <table id="classment"> + <thead> + <th>Classement</th> + <th>Équipe</th> + <th>Heure de passage</th> + </thead> + <tbody id="classment-body"> + </tbody> + </table> + </div> + <script> + window.addEventListener("load", function() { + const EDITIONS = "http://localhost:8000/editions"; + const ENTRY = "http://localhost:8000/entry?year="; + + let year = 2022; + let classment = document.getElementById("classment-body"); + let btn_display = document.getElementById("btn_display_classment"); + let refresh = 1000; //ms to refresh + + btn_display.addEventListener("click", function(){ + getClassment(); + }); + + function getClassment() { + classment.innerHTML = ""; + let entries_url = ENTRY + year; + fetch(entries_url) + .then((response) => response.json()) + .then((entries_data) => { + for (let i in entries_data) { + let tr = document.createElement("tr"); + let td1 = document.createElement("td"); + let td2 = document.createElement("td"); + let td3 = document.createElement("td"); + + td1.innerHTML = i; + td2.innerHTML = entries_data[i].name; + td3.innerHTML = parseTimeStamp(entries_data[i].time_stamp); + + tr.appendChild(td1); + tr.appendChild(td2); + tr.appendChild(td3); + + classment.appendChild(tr); + } + }); + } + + function parseTimeStamp(time_stamp) { + return time_stamp.split("T")[1].split(".")[0]; + } + + getClassment(); + + }) + + </script> +</body> +</html> \ No newline at end of file diff --git a/frontend/.dockerignore b/frontend/.dockerignore new file mode 100644 index 0000000000000000000000000000000000000000..b512c09d476623ff4bf8d0d63c29b784925dbdf8 --- /dev/null +++ b/frontend/.dockerignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 791d28af5e5d65a02548212312889c915ce8217d..31a75aa80516b92ed9b72ecadfb8712fef44c47a 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,15 +1,13 @@ -FROM node:latest - -RUN mkdir -p /usr/app/node_modules && chown -R node:node /usr/app +FROM node:16 WORKDIR /usr/app -COPY package.json . - -USER node +COPY package*.json ./ RUN npm install -COPY --chown=node:node . . +COPY . . + +ENV PORT=5173 -EXPOSE 5173 +EXPOSE 5173 \ No newline at end of file