first exchange between front and back no database

This commit is contained in:
kinou-p 2023-03-22 14:03:35 +01:00
parent e77b99c31e
commit 9c9d855722
12 changed files with 111 additions and 70 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
#.env
backend/node_modules/

View File

View File

@ -19,12 +19,12 @@
"integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg=="
},
"body-parser": {
"version": "1.20.1",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz",
"integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==",
"version": "1.20.2",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz",
"integrity": "sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==",
"requires": {
"bytes": "3.1.2",
"content-type": "~1.0.4",
"content-type": "~1.0.5",
"debug": "2.6.9",
"depd": "2.0.0",
"destroy": "1.2.0",
@ -32,7 +32,7 @@
"iconv-lite": "0.4.24",
"on-finished": "2.4.1",
"qs": "6.11.0",
"raw-body": "2.5.1",
"raw-body": "2.5.2",
"type-is": "~1.6.18",
"unpipe": "1.0.0"
}
@ -148,6 +148,38 @@
"type-is": "~1.6.18",
"utils-merge": "1.0.1",
"vary": "~1.1.2"
},
"dependencies": {
"body-parser": {
"version": "1.20.1",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz",
"integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==",
"requires": {
"bytes": "3.1.2",
"content-type": "~1.0.4",
"debug": "2.6.9",
"depd": "2.0.0",
"destroy": "1.2.0",
"http-errors": "2.0.0",
"iconv-lite": "0.4.24",
"on-finished": "2.4.1",
"qs": "6.11.0",
"raw-body": "2.5.1",
"type-is": "~1.6.18",
"unpipe": "1.0.0"
}
},
"raw-body": {
"version": "2.5.1",
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz",
"integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==",
"requires": {
"bytes": "3.1.2",
"http-errors": "2.0.0",
"iconv-lite": "0.4.24",
"unpipe": "1.0.0"
}
}
}
},
"finalhandler": {
@ -321,9 +353,9 @@
"integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg=="
},
"raw-body": {
"version": "2.5.1",
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz",
"integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==",
"version": "2.5.2",
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz",
"integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==",
"requires": {
"bytes": "3.1.2",
"http-errors": "2.0.0",

View File

@ -8,6 +8,7 @@
"start": "node server.js"
},
"dependencies": {
"body-parser": "^1.20.2",
"express": "^4.18.2"
},
"devDependencies": {},

View File

@ -1,46 +1,22 @@
// const http = require('https');
// const host = 'localhost';
// const port = 443;
// // const server = http.createServer((req, res) => {
// // res.end('Voilà la réponse du serveur !');
// // });
// const requestListener = function (req, res) {
// res.writeHead(200);
// res.end("My first server!");
// };
// const server = http.createServer(requestListener);
// server.listen(port, host, () => {
// console.log(`Server is running on http://${host}:${port}`);
// });
// 'use strict';
// const express = require('express');
// const app = express();
// app.get('/', (req, res) => {
// res.send('Hello World!')
// })
// app.listen(5000, () => console.log('Server is up and running'));
// const express = require('express')
// const app = express()
// const port = 5000
// const name = process.env.name || "World"
// app.get('/', (req, res) => {
// res.send(`Hello ${name} !`)
// })
// app.listen(port, () => {
// console.log(`Server Started on Port ${port}`)
// })
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.get('/', (req, res) => {
res.sendfile('/var/www/html')
// app.use(express.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.get('/api/test', (req, res) => {
res.send('Hello World!')
})
app.post('/api/login', (req, res) => {
// const formData = req.body;
// console.log(formData);
console.log('get request');
console.log(req.body);
res.status(201).json(req.body);
});
app.listen(5000, () => console.log('Server is up and running'));

View File

@ -10,23 +10,28 @@
# }
server {
listen 443 ssl;
listen 80 ssl;
# listen 443 ssl;
#listen 80;
# listen 80 ssl;
# listen 443 ssl;
listen 80;
# server_name homemadePong.42.fr;
ssl_protocols TLSv1.3;
ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
# ssl_protocols TLSv1.3;
# ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
# ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
# root /var/www/html;
# index index.html;
# autoindex on;
location / {
root /var/www/html;
index index.html;
}
location /api/login {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@ -34,6 +39,8 @@ server {
proxy_pass http://backend:5000;
}
#proxy_pass http://localhost:5000
}

View File

@ -14,7 +14,8 @@ services:
ports:
- 80:80
# - 443:443
volumes:
- ./frontend:/var/www/html
restart: unless-stopped
networks:
- pongNetwork

View File

@ -6,7 +6,7 @@
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/03/19 09:28:33 by apommier #+# #+# #
# Updated: 2023/03/20 21:24:40 by apommier ### ########.fr #
# Updated: 2023/03/22 12:14:35 by apommier ### ########.fr #
# #
# **************************************************************************** #
@ -27,7 +27,8 @@ FROM node:latest
WORKDIR /usr/src/app
COPY /backend/package*.json ./
RUN npm install
#npm install body-parser
COPY /backend/ .
EXPOSE 5000
CMD ["npm", "start"]
# CMD ["node", "server.js"]
# CMD ["npm", "start"]
CMD ["node", "server.js"]

View File

@ -6,17 +6,17 @@
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/03/19 09:28:32 by apommier #+# #+# #
# Updated: 2023/03/20 19:48:53 by apommier ### ########.fr #
# Updated: 2023/03/21 11:08:16 by apommier ### ########.fr #
# #
# **************************************************************************** #
FROM nginx:latest
RUN apt update -y
RUN apt-get install -y openssl
# RUN apt update -y
# RUN apt-get install -y openssl
RUN mkdir -p /etc/ssl/private
RUN mkdir -p /etc/ssl/certs
RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/nginx-selfsigned.key -out /etc/ssl/certs/nginx-selfsigned.crt -subj "/C=FR/ST=17/L=StJeanDeLiversay/O=42/CN=apommier"
# RUN mkdir -p /etc/ssl/private
# RUN mkdir -p /etc/ssl/certs
# RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/nginx-selfsigned.key -out /etc/ssl/certs/nginx-selfsigned.crt -subj "/C=FR/ST=17/L=StJeanDeLiversay/O=42/CN=apommier"
COPY conf/nginx.conf /etc/nginx/conf.d/default.conf

View File

@ -42,6 +42,11 @@ footer {
margin:auto;
}
.submit{
height: 5vh;
border-radius: 100vh;
}
.submit:hover {
background-color: blueviolet;
}

View File

@ -4,6 +4,7 @@
<meta charset="utf-8">
<link href="./css/header.css" rel="stylesheet">
<title>BEST PONG EVER</title>
<script src="./js/login.js"></script>
</head>
<body>
<div class="header">
@ -21,14 +22,24 @@
</div>
<div class ="login">
<form method="get" name="login" action="" class ="loginForm">
<form id="loginForm" method="post" name="login" action="/api/login" class ="loginForm">
<p class="loginHere">Login Here</p>
<!-- <input type="text" name="prenom"> -->
<!-- <label>Login</label> : -->
<input type="text" name="login" placeholder="login">
<!-- <label>Password</label> : -->
<input type="text" name="password" placeholder="password">
<input class="submit" type="button" value="LOGIN">
<!-- <input class="submit" type="button" value="LOGIN" onclick="login()"> -->
<button class="submit" onclick="login()">LOGIN</button>
<!-- <script>
function login()
{
alert("Le bouton a été cliqué !");
var formulaire = document.getElementById("loginForm");
formulaire.submit();
}
</script> -->
<!-- <p>Texte à l'intérieur du formulaire</p> -->
</form>
<!-- <p>Texte après le formulaire</p>-->

6
frontend/js/login.js Normal file
View File

@ -0,0 +1,6 @@
function login()
{
alert("Le bouton a été cliqué !");
var formulaire = document.getElementById("loginForm");
formulaire.submit();
}