diff --git a/README.md b/README.md index 258c202..2d65b08 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,26 @@ **Projet Chat** +**Instruction de lancement du Chat** +- `docker compose up` +- Puis se connecter en local sur `http://localhost:4200` +- Le client ne se connecte pas pour l'instant. Mais le serveur démarre enfin, problème entre toutes les images docker, + seul l'image des bases de données MongoDB et l'image du service-authentication marche. Les deux autres services + ne marchent pas en image docker à cause du socket pour je ne sais quelle raison. + +Pour lancer le projet sans image docker, il est obligatoire de lancer plusieurs terminals pour le frontend et pour chaque +serveurs et avoir des images dockers mongodb. +A savoir: +- Terminal Frontend dans le dossier frontend : `ng serve` +- Terminal service-authentication dans le dossier service-authentication : `node server.js` +- Terminal service-message dans le dossier service-message : `node server.js` +- Terminal service-privateroom dans le dossier service-privateroom : `node server.js` +- Puis se connecter en local sur `http://localhost:4200` + + + + + +**Instruction du professeur** Le but du projet est de fournir un service de chat rudimentaire : - Une interface utilisateur en web - Les utilisateurs peuvent s'enregistrer/se connecter/se déconnecter/changer leur mot de passe diff --git a/backend/service-authentication/server.js b/backend/service-authentication/server.js index 1102b60..20db095 100644 --- a/backend/service-authentication/server.js +++ b/backend/service-authentication/server.js @@ -10,7 +10,7 @@ app.use(bodyParser.urlencoded({extended:true})); app.use(bodyParser.json()); const cors = require('cors'); -app.use(cors({origin: 'http://127.0.0.1:4200', credentials: true})); +app.use(cors({origin: 'http://localhost:4200', credentials: true})); const mongoConnect = require('./mongodbConnect'); diff --git a/backend/service-message/auth.js b/backend/service-message/auth.js index 2cd2d5a..a2f1364 100644 --- a/backend/service-message/auth.js +++ b/backend/service-message/auth.js @@ -7,14 +7,20 @@ function getSession (req, callback) { url: 'http://127.0.0.1:3000/verify:token', body: 'sessionid='+req.headers.cookie.replace('SESSIONID=','') },function (error, response, body) { - const bodyJson = JSON.parse(body); - if (bodyJson && bodyJson.status && bodyJson.data) { - if (bodyJson.status === 'ok') { - return callback(bodyJson.data.token); - } else { - return callback(bodyJson.data.reason); + console.log("body ; getSession auth message :",body); + if(typeof body !== 'undefined'){ + const bodyJson = JSON.parse(body); + if (bodyJson && bodyJson.status && bodyJson.data) { + if (bodyJson.status === 'ok') { + return callback(bodyJson.data.token); + } else { + return callback(bodyJson.data.reason); + } } } + else{ + return callback('Error'); + } }); } return callback(undefined); diff --git a/backend/service-message/server.js b/backend/service-message/server.js index 934abdf..13f0614 100644 --- a/backend/service-message/server.js +++ b/backend/service-message/server.js @@ -11,7 +11,7 @@ const app = express(); const server = http.createServer(app); const io = new Server(server, { cors: { - origin: "http://127.0.0.1:4200", + origin: "http://localhost:4200", methods: ["GET", "POST"], credentials: true } @@ -19,7 +19,7 @@ const io = new Server(server, { const port = process.env.PORT || 3001; app.use(bodyParser.json()); -app.use(cors({origin: 'http://127.0.0.1:4200', credentials: true})); +app.use(cors({origin: 'http://localhost:4200', credentials: true})); app.use(cookieParser()); @@ -114,6 +114,6 @@ io.on('connection',socket => { }); }); -server.listen(port, '0.0.0.0',() => { +server.listen(port,'0.0.0.0', () => { console.log (`listening on port ${port}`); }); \ No newline at end of file diff --git a/backend/service-privateroom/auth.js b/backend/service-privateroom/auth.js index 2cd2d5a..c50c02f 100644 --- a/backend/service-privateroom/auth.js +++ b/backend/service-privateroom/auth.js @@ -7,14 +7,20 @@ function getSession (req, callback) { url: 'http://127.0.0.1:3000/verify:token', body: 'sessionid='+req.headers.cookie.replace('SESSIONID=','') },function (error, response, body) { - const bodyJson = JSON.parse(body); - if (bodyJson && bodyJson.status && bodyJson.data) { - if (bodyJson.status === 'ok') { - return callback(bodyJson.data.token); - } else { - return callback(bodyJson.data.reason); + console.log("body ; getSession auth private :",body); + if(typeof body !== 'undefined'){ + const bodyJson = JSON.parse(body); + if (bodyJson && bodyJson.status && bodyJson.data) { + if (bodyJson.status === 'ok') { + return callback(bodyJson.data.token); + } else { + return callback(bodyJson.data.reason); + } } } + else{ + return callback('Error'); + } }); } return callback(undefined); diff --git a/backend/service-privateroom/server.js b/backend/service-privateroom/server.js index d42f17d..fde3ae3 100644 --- a/backend/service-privateroom/server.js +++ b/backend/service-privateroom/server.js @@ -6,7 +6,7 @@ const { Server } = require("socket.io"); const server = http.createServer(app); const io = new Server(server, { cors: { - origin: "http://127.0.0.1:4200", + origin: "http://localhost:4200", methods: ["GET", "POST"], credentials: true } @@ -20,7 +20,7 @@ const cookieParser = require('cookie-parser'); app.use(cookieParser()); const cors = require('cors'); -app.use(cors({origin: 'http://127.0.0.1:4200', credentials: true})); +app.use(cors({origin: 'http://localhost:4200', credentials: true})); const auth = require("./auth"); diff --git a/docker-compose.yml b/docker-compose.yml index 6c0bf60..8d20db4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,9 +13,11 @@ services: depends_on: - service-authentication - service-message + - service-privateroom links: - service-authentication - service-message + - service-privateroom service-authentication: container_name: service-authentication @@ -42,7 +44,7 @@ services: - backend/service-message - backend/service-message/node_modules ports: - - 3001:3000 + - 3001:3001 depends_on: - mongodb-message links: @@ -58,7 +60,7 @@ services: - backend/service-privateroom - backend/service-privateroom/node_modules ports: - - 3002:3000 + - 3002:3002 depends_on: - mongodb-privateroom links: diff --git a/frontend/src/environments/environment.prod.ts b/frontend/src/environments/environment.prod.ts index 9435806..9a0bcc3 100644 --- a/frontend/src/environments/environment.prod.ts +++ b/frontend/src/environments/environment.prod.ts @@ -1,6 +1,6 @@ export const environment = { production: true, - urlCL: 'http://127.0.0.1:3000', - urlCG: 'http://127.0.0.1:3001', - urlCPR: 'http://127.0.0.1:3002' + urlCL: 'http://localhost:3000', + urlCG: 'http://localhost:3001', + urlCPR: 'http://localhost:3002' }; diff --git a/frontend/src/environments/environment.ts b/frontend/src/environments/environment.ts index d92f503..78c183b 100644 --- a/frontend/src/environments/environment.ts +++ b/frontend/src/environments/environment.ts @@ -4,9 +4,9 @@ export const environment = { production: false, - urlCL: 'http://127.0.0.1:3000', - urlCG: 'http://127.0.0.1:3001', - urlCPR: 'http://127.0.0.1:3002' + urlCL: 'http://localhost:3000', + urlCG: 'http://localhost:3001', + urlCPR: 'http://localhost:3002' }; /*