diff --git a/encheres/server/controllers/HtmlResponseBuilder.js b/encheres/server/controllers/HtmlResponseBuilder.js deleted file mode 100644 index a51f8aa2fed272569985b0a1d87fdf2e57a408c5..0000000000000000000000000000000000000000 --- a/encheres/server/controllers/HtmlResponseBuilder.js +++ /dev/null @@ -1,12 +0,0 @@ - -export default class HtmlResponseBuilder { - - response; - url; - - constructor(url, response) { - this.url = url; - this.response =response; - } - -} \ No newline at end of file diff --git a/encheres/server/controllers/RequestController.js b/encheres/server/controllers/RequestController.js index 23f0f85dd1114c6fe1a944b1bd23aae41325ac0f..a8fbfaeecb02cb2ac8740d00794968064a0ed56d 100644 --- a/encheres/server/controllers/RequestController.js +++ b/encheres/server/controllers/RequestController.js @@ -32,8 +32,8 @@ export default class RequestController { this.response.end(); } - buildResponse() { - new ResponseBuilder(this.url, this.#response).handleResponse(); + async buildResponse() { + await new ResponseBuilder(this.url, this.#response).handleResponse(); } } \ No newline at end of file diff --git a/encheres/server/controllers/ResponseBuilder.js b/encheres/server/controllers/ResponseBuilder.js index c0b10973ee7c4dec0ddbcfc024003aa1189e067a..67df9f5f5df560b4f88187bcd9c5cae1ce7cb5c8 100644 --- a/encheres/server/controllers/ResponseBuilder.js +++ b/encheres/server/controllers/ResponseBuilder.js @@ -1,8 +1,5 @@ -import defaultBuilder from './default.js'; -import aboutBuilder from './about.js'; -import auctioneerBuilder from './auctioneer.js' +import * as fs from 'fs/promises'; import ErrorResponseBuilder from './ErrorResponseBuilder.js'; -import bidderBuilder from './bidder.js'; import { URL } from 'url'; export default class ResponseBuilder { @@ -27,28 +24,44 @@ export default class ResponseBuilder { return this.#request; } - handleResponse() { - this.buildResponse(); + async handleResponse() { + await this.buildResponse(); } - buildResponse() { + async buildResponse() { // routage "à la main" if (this.url === '/' ){ - new defaultBuilder(this.url, this.response).buildResponse(); + await this.readResponse('./public/index.html'); } else if (this.url.startsWith('/about')){ - new aboutBuilder(this.url, this.response).buildResponse(); + await this.readResponse('./public/html/about.html'); } else if(this.url.startsWith('/auctioneer')) { - new auctioneerBuilder(this.url, this.response).buildResponse(); + await this.readResponse('./public/html/auctioneer.html'); } else if(this.url.startsWith('/bidder')) { - new bidderBuilder(this.url, this.response).buildResponse(); + await this.readResponse('./public/html/bidder.html'); } else { - new ErrorResponseBuilder(this.url, this.response, 404).handleError(); + await this.readResponse(`./public${this.#url}`); } } + async readResponse(file) { + try { + // check if resource is available + await fs.access(file); + // read the requested resource content + const data = await fs.readFile(file); + // send resource content + this.response.statusCode = 200; + this.response.write(data); + } + catch(err) { // resource is not available + new ErrorResponseBuilder(this.url, this.response, 404).handleError(); + } + } + + } \ No newline at end of file diff --git a/encheres/server/controllers/about.js b/encheres/server/controllers/about.js deleted file mode 100644 index fd890ab5b1b8c56babca36107ef4baf8ac3538e5..0000000000000000000000000000000000000000 --- a/encheres/server/controllers/about.js +++ /dev/null @@ -1,24 +0,0 @@ -import HtmlResponseBuilder from "./HtmlResponseBuilder.js"; -import * as fs from 'fs'; - - -export default class about extends HtmlResponseBuilder{ - - constructor(url, response){ - super(url, response); - } - - buildResponse() { - let path = `..${this.url}.html`; - try { - fs.accessSync(path, fs.constants.R_OK); - const content = fs.readFileSync(path); - this.response.write(content); - this.response.end(); - }catch(err) { - new ErrorResponseBuilder(this.url, this.response, 404).handleError(); - } - - } - -} \ No newline at end of file diff --git a/encheres/server/controllers/auctioneer.js b/encheres/server/controllers/auctioneer.js deleted file mode 100644 index 2f52a85f7d8931d0cdf6ac35346d62d9b01f053e..0000000000000000000000000000000000000000 --- a/encheres/server/controllers/auctioneer.js +++ /dev/null @@ -1,22 +0,0 @@ -import HtmlResponseBuilder from "./HtmlResponseBuilder.js"; -import * as fs from 'fs'; - -export default class auctioneer extends HtmlResponseBuilder{ - - constructor(url, response){ - super(url, response); - } - - buildResponse() { - let path = `..${this.url}.html`; - try { - fs.accessSync(path, fs.constants.R_OK); - const content = fs.readFileSync(path); - this.response.write(content); - }catch(err) { - new ErrorResponseBuilder(this.url, this.response, 404).handleError(); - } - - } - -} \ No newline at end of file diff --git a/encheres/server/controllers/bidder.js b/encheres/server/controllers/bidder.js deleted file mode 100644 index e0f1dbb7964a638a02c0f71056e95b9857400d21..0000000000000000000000000000000000000000 --- a/encheres/server/controllers/bidder.js +++ /dev/null @@ -1,22 +0,0 @@ -import HtmlResponseBuilder from "./HtmlResponseBuilder.js"; -import * as fs from 'fs'; - -export default class bidder extends HtmlResponseBuilder{ - - constructor(url, response){ - super(url, response); - } - - buildResponse() { - let path = `..${this.url}.html`; - try { - fs.accessSync(path, fs.constants.R_OK); - const content = fs.readFileSync(path); - this.response.write(content); - }catch(err) { - new ErrorResponseBuilder(this.url, this.response, 404).handleError(); - } - - } - -} \ No newline at end of file diff --git a/encheres/server/controllers/default.js b/encheres/server/controllers/default.js deleted file mode 100644 index 59126338c28b99ad20b59f5b1aa1a96dcb783021..0000000000000000000000000000000000000000 --- a/encheres/server/controllers/default.js +++ /dev/null @@ -1,29 +0,0 @@ -import HtmlResponseBuilder from "./HtmlResponseBuilder.js"; -import * as fs from 'fs'; - -import ErrorResponseBuilder from "./ErrorResponseBuilder.js"; - - -export default class defaultBuilder extends HtmlResponseBuilder{ - - constructor(url, response){ - super(url, response); - } - - /** - * send the requested resource as it is, if it exists, else responds with a 404 - */ - buildResponse() { - const path = `..${this.url}index.html`; - try { - console.log(path); - fs.accessSync(path, fs.constants.R_OK); - const content = fs.readFileSync(path); - this.response.write(content); - }catch(err) { - new ErrorResponseBuilder(this.url, this.response, 404).handleError(); - } - - } - -} \ No newline at end of file diff --git a/encheres/server/controllers/ioController.js b/encheres/server/controllers/ioController.js index 9ec5381fe1d57e4d03832779281cc19f7ea30e29..75de8eee674fad505c2863d7c9776b282c07bf20 100644 --- a/encheres/server/controllers/ioController.js +++ b/encheres/server/controllers/ioController.js @@ -6,7 +6,7 @@ export default class IOController { constructor(io) { this.#io = io; - this.#clients = new Map(); + //this.#clients = new Map(); } registerSocket(socket) { @@ -17,14 +17,12 @@ export default class IOController { setupListeners(socket) { socket.on( 'pong', () => this.greatings(socket) ); - socket.on( 'disconnect' , () => this.leave(socket) ); + //socket.on( 'disconnect' , () => this.leave(socket) ); } greatings(socket) { console.log(`pong received from (id : ${socket.id}) at ${new Date().toLocaleTimeString()}`); - //const timerId = setInterval(this.randomNumber.bind(this), this.#interval); - //const timerId = setInterval(this.randomNumber.bind(this), this.#interval, socket); /**si on veut que le nombre random soit différent */ - this.#clients.set(socket.id, timerId); + //this.#clients.set(socket.id); } leave(socket) { diff --git a/encheres/server/main.js b/encheres/server/main.js index 9a1144e0a64c5f275d19f89c37bdb7f4a6b09e0d..538ffe70d7b56c14f6ef4bca15013c0046026c29 100644 --- a/encheres/server/main.js +++ b/encheres/server/main.js @@ -8,6 +8,11 @@ const server = http.createServer( (request, response) => new RequestController(request, response).handleRequest() ); +const io = new ServerIO(server); + +// mise en place du serveur de socket.io +const ioController = new IOController(io); +io.on('connection', ioController.registerSocket.bind(ioController) ); server.listen(8080); \ No newline at end of file diff --git a/encheres/server/public/html/about.html b/encheres/server/public/html/about.html new file mode 100644 index 0000000000000000000000000000000000000000..1199e9dd14211193bfd5ba42d48659b1d4231382 --- /dev/null +++ b/encheres/server/public/html/about.html @@ -0,0 +1,12 @@ +<!DOCTYPE html> + +<html> + <head> + <meta charset="UTF-8"> + <title>Server</title> + <link href="./style/style.css" rel="stylesheet" type="text/css"/> + </head> + + <body> + <h1>Infos</h1> + </body> \ No newline at end of file diff --git a/encheres/server/public/html/auctioneer.html b/encheres/server/public/html/auctioneer.html new file mode 100644 index 0000000000000000000000000000000000000000..74b7c4735bc721c74f1df33c947ffca8d54da174 --- /dev/null +++ b/encheres/server/public/html/auctioneer.html @@ -0,0 +1,15 @@ +<!DOCTYPE html> + +<html> + <head> + <meta charset="UTF-8"> + <title>Server</title> + <link href="./style/style.css" rel="stylesheet" type="text/css"/> + <script src="/socket.io/socket.io.js"></script> + <script defer src="../scripts/auctioneer-bundle.js?8646d609246098631a96"></script></head> + + <body> + <h1>Comissaire-priseur</h1> + </body> + +</html> \ No newline at end of file diff --git a/encheres/server/public/html/bidder.html b/encheres/server/public/html/bidder.html new file mode 100644 index 0000000000000000000000000000000000000000..f053e67c279777efae1b356850a6f48bc1fa3e13 --- /dev/null +++ b/encheres/server/public/html/bidder.html @@ -0,0 +1,15 @@ +<!DOCTYPE html> + +<html> + <head> + <meta charset="UTF-8"> + <title>Server</title> + <link href="./style/style.css" rel="stylesheet" type="text/css"/> + <script src="/socket.io/socket.io.js"></script> + <script defer src="../scripts/bidder-bundle.js?8646d609246098631a96"></script></head> + + <body> + <h1>Enchérisseur</h1> + </body> + +</html> \ No newline at end of file diff --git a/encheres/server/public/index.html b/encheres/server/public/index.html index 121c59332a0c66f35201924ffb5325947e852f0a..f1f72bba793e1724075e192fb4be20bf769e5dc0 100644 --- a/encheres/server/public/index.html +++ b/encheres/server/public/index.html @@ -1 +1,22 @@ -<head><script defer src="scripts/bundle.js?50d73e68ded995014797"></script></head> \ No newline at end of file +<!DOCTYPE html> + +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr"> + + <head> + <meta charset="UTF-8"/> + <title>server</title> + <link href="./style/style.css" rel="stylesheet" type="text/css"/> + + <script defer src="scripts/main-bundle.js?8646d609246098631a96"></script></head> + + <body> + <h1>Enchères</h1> + <p class="ok"></p> + <ul id="liens"> + <li> <a href="./auctioneer">Etre Comissaire-priseur</a> </li> + <li> <a href="./bidder">Participer aux Enchères</a> </li> + <li> <a href="./about">Infos sur l'application</a> </li> + </ul> + </body> + +</html> \ No newline at end of file diff --git a/encheres/server/public/scripts/auctioneer-bundle.js b/encheres/server/public/scripts/auctioneer-bundle.js new file mode 100644 index 0000000000000000000000000000000000000000..f857f6d69b8c280b37c23e09c0484491f15cd953 --- /dev/null +++ b/encheres/server/public/scripts/auctioneer-bundle.js @@ -0,0 +1,2 @@ +/*! For license information please see auctioneer-bundle.js.LICENSE.txt */ +(()=>{var __webpack_modules__={"./src/scripts/auctioneer.js":()=>{eval("console.log('le bundle-auctioneer a été généré');\nconst socket = io();//# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiLi9zcmMvc2NyaXB0cy9hdWN0aW9uZWVyLmpzIiwibmFtZXMiOlsiY29uc29sZSIsImxvZyIsInNvY2tldCIsImlvIl0sInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly9hcHAvLi9zcmMvc2NyaXB0cy9hdWN0aW9uZWVyLmpzP2U2NjIiXSwic291cmNlc0NvbnRlbnQiOlsiY29uc29sZS5sb2coJ2xlIGJ1bmRsZS1hdWN0aW9uZWVyIGEgw6l0w6kgZ8OpbsOpcsOpJyk7XHJcblxyXG5jb25zdCBzb2NrZXQgPSBpbygpO1xyXG4iXSwibWFwcGluZ3MiOiJBQUFBQSxPQUFPLENBQUNDLEdBQUcsQ0FBQyxtQ0FBbUMsQ0FBQztBQUVoRCxNQUFNQyxNQUFNLEdBQUdDLEVBQUUsQ0FBQyxDQUFDIn0=\n//# sourceURL=webpack-internal:///./src/scripts/auctioneer.js\n")}},__webpack_exports__={};__webpack_modules__["./src/scripts/auctioneer.js"]()})(); \ No newline at end of file diff --git a/encheres/server/public/scripts/auctioneer-bundle.js.LICENSE.txt b/encheres/server/public/scripts/auctioneer-bundle.js.LICENSE.txt new file mode 100644 index 0000000000000000000000000000000000000000..fb879f6a7edf8cf3a1172fa2a8e978332467d78a --- /dev/null +++ b/encheres/server/public/scripts/auctioneer-bundle.js.LICENSE.txt @@ -0,0 +1,3 @@ +/*!***********************************!*\ + !*** ./src/scripts/auctioneer.js ***! + \***********************************/ diff --git a/encheres/server/public/scripts/bidder-bundle.js b/encheres/server/public/scripts/bidder-bundle.js new file mode 100644 index 0000000000000000000000000000000000000000..36081fbec2cfc9cfb3b7df492f318040f967349f --- /dev/null +++ b/encheres/server/public/scripts/bidder-bundle.js @@ -0,0 +1,2 @@ +/*! For license information please see bidder-bundle.js.LICENSE.txt */ +(()=>{var __webpack_modules__={"./src/scripts/bidder.js":()=>{eval("console.log('le bundle-bidder a été généré');\nconst socket = io();//# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiLi9zcmMvc2NyaXB0cy9iaWRkZXIuanMiLCJuYW1lcyI6WyJjb25zb2xlIiwibG9nIiwic29ja2V0IiwiaW8iXSwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsid2VicGFjazovL2FwcC8uL3NyYy9zY3JpcHRzL2JpZGRlci5qcz9hNjJhIl0sInNvdXJjZXNDb250ZW50IjpbImNvbnNvbGUubG9nKCdsZSBidW5kbGUtYmlkZGVyIGEgw6l0w6kgZ8OpbsOpcsOpJyk7XHJcblxyXG5jb25zdCBzb2NrZXQgPSBpbygpOyJdLCJtYXBwaW5ncyI6IkFBQUFBLE9BQU8sQ0FBQ0MsR0FBRyxDQUFDLCtCQUErQixDQUFDO0FBRTVDLE1BQU1DLE1BQU0sR0FBR0MsRUFBRSxDQUFDLENBQUMifQ==\n//# sourceURL=webpack-internal:///./src/scripts/bidder.js\n")}},__webpack_exports__={};__webpack_modules__["./src/scripts/bidder.js"]()})(); \ No newline at end of file diff --git a/encheres/server/public/scripts/bidder-bundle.js.LICENSE.txt b/encheres/server/public/scripts/bidder-bundle.js.LICENSE.txt new file mode 100644 index 0000000000000000000000000000000000000000..84cd2c52bf6f3d1841205b9005d14587c107ed17 --- /dev/null +++ b/encheres/server/public/scripts/bidder-bundle.js.LICENSE.txt @@ -0,0 +1,3 @@ +/*!*******************************!*\ + !*** ./src/scripts/bidder.js ***! + \*******************************/ diff --git a/encheres/server/public/scripts/bundle.js b/encheres/server/public/scripts/bundle.js deleted file mode 100644 index b11f4fd027562d010cd11e1757bcec01a00cdb3d..0000000000000000000000000000000000000000 --- a/encheres/server/public/scripts/bundle.js +++ /dev/null @@ -1,2 +0,0 @@ -/*! For license information please see bundle.js.LICENSE.txt */ -(()=>{var __webpack_modules__={"./src/scripts/main.js":()=>{eval("// write your code here\nconsole.log('le bundle a été généré');\nconst socket = io();//# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiLi9zcmMvc2NyaXB0cy9tYWluLmpzIiwibmFtZXMiOlsiY29uc29sZSIsImxvZyIsInNvY2tldCIsImlvIl0sInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly9hcHAvLi9zcmMvc2NyaXB0cy9tYWluLmpzPzI5NjMiXSwic291cmNlc0NvbnRlbnQiOlsiLy8gd3JpdGUgeW91ciBjb2RlIGhlcmVcbmNvbnNvbGUubG9nKCdsZSBidW5kbGUgYSDDqXTDqSBnw6luw6lyw6knKTtcblxuY29uc3Qgc29ja2V0ID0gaW8oKTtcblxuXG4iXSwibWFwcGluZ3MiOiJBQUFBO0FBQ0FBLE9BQU8sQ0FBQ0MsR0FBRyxDQUFDLHdCQUF3QixDQUFDO0FBRXJDLE1BQU1DLE1BQU0sR0FBR0MsRUFBRSxDQUFDLENBQUMifQ==\n//# sourceURL=webpack-internal:///./src/scripts/main.js\n")}},__webpack_exports__={};__webpack_modules__["./src/scripts/main.js"]()})(); \ No newline at end of file diff --git a/encheres/server/public/scripts/main-bundle.js b/encheres/server/public/scripts/main-bundle.js new file mode 100644 index 0000000000000000000000000000000000000000..983ac6db2d0f151edca73fea76c24113287de062 --- /dev/null +++ b/encheres/server/public/scripts/main-bundle.js @@ -0,0 +1,2 @@ +/*! For license information please see main-bundle.js.LICENSE.txt */ +(()=>{var __webpack_modules__={"./src/scripts/main.js":()=>{eval("// write your code here\nconsole.log('le bundle a été généré');//# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiLi9zcmMvc2NyaXB0cy9tYWluLmpzIiwibmFtZXMiOlsiY29uc29sZSIsImxvZyJdLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJ3ZWJwYWNrOi8vYXBwLy4vc3JjL3NjcmlwdHMvbWFpbi5qcz8yOTYzIl0sInNvdXJjZXNDb250ZW50IjpbIi8vIHdyaXRlIHlvdXIgY29kZSBoZXJlXG5jb25zb2xlLmxvZygnbGUgYnVuZGxlIGEgw6l0w6kgZ8OpbsOpcsOpJyk7XG5cblxuICAiXSwibWFwcGluZ3MiOiJBQUFBO0FBQ0FBLE9BQU8sQ0FBQ0MsR0FBRyxDQUFDLHdCQUF3QixDQUFDIn0=\n//# sourceURL=webpack-internal:///./src/scripts/main.js\n")}},__webpack_exports__={};__webpack_modules__["./src/scripts/main.js"]()})(); \ No newline at end of file diff --git a/encheres/server/public/scripts/bundle.js.LICENSE.txt b/encheres/server/public/scripts/main-bundle.js.LICENSE.txt similarity index 100% rename from encheres/server/public/scripts/bundle.js.LICENSE.txt rename to encheres/server/public/scripts/main-bundle.js.LICENSE.txt