From c0c21aeeb852b9f061fd9055339299e6b9b554a9 Mon Sep 17 00:00:00 2001 From: Quentin Roussel Date: Wed, 27 Mar 2024 23:55:53 +0100 Subject: [PATCH] attempt to use https --- traque-back/.gitignore | 4 ++++ traque-back/Makefile | 8 ++++++++ traque-back/index.js | 19 +++++++++++-------- traque-front/.gitignore | 2 ++ traque-front/components/team/actionDrawer.jsx | 2 +- traque-front/components/team/loginForm.jsx | 2 +- traque-front/context/socketContext.jsx | 4 +++- traque-front/package.json | 2 +- 8 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 traque-back/Makefile diff --git a/traque-back/.gitignore b/traque-back/.gitignore index c6bba59..68e2ef9 100644 --- a/traque-back/.gitignore +++ b/traque-back/.gitignore @@ -1,3 +1,7 @@ +#https dev certificates +csr.pem +key.pem +server.crt # Logs logs *.log diff --git a/traque-back/Makefile b/traque-back/Makefile new file mode 100644 index 0000000..75f93ad --- /dev/null +++ b/traque-back/Makefile @@ -0,0 +1,8 @@ +#Make a self signed certificate for development +keys: key.pem server.crt + +key.pem csr.pem: + openssl req -newkey rsa:2048 -new -nodes -keyout key.pem -out csr.pem + +server.crt: key.pem csr.pem + openssl x509 -req -days 365 -in csr.pem -signkey key.pem -out server.crt \ No newline at end of file diff --git a/traque-back/index.js b/traque-back/index.js index aec86fa..eba7493 100644 --- a/traque-back/index.js +++ b/traque-back/index.js @@ -1,19 +1,26 @@ -import { createServer } from "http"; +import { createServer } from "https"; import { Server } from "socket.io"; import Game from "./game.js"; import { config } from "dotenv"; +import { readFileSync } from "fs"; //extract admin password from .env file config(); const ADMIN_PASSWORD = process.env.ADMIN_PASSWORD; const HOST = process.env.HOST; const PORT = process.env.PORT; -const httpServer = createServer(); -//Password that socket clients will have to send to be able to send admin commands +const httpsServer = createServer({ + key: readFileSync(process.env.SSL_KEY, 'utf-8'), + cert: readFileSync(process.env.SSL_CERT, 'utf-8') +}); + +httpsServer.listen(PORT, HOST, () => { + console.log(`Server running`); +}); //set cors to allow all origins -const io = new Server(httpServer, { +const io = new Server(httpsServer, { cors: { origin: "*", methods: ["GET", "POST"] @@ -195,7 +202,3 @@ io.of("player").on("connection", (socket) => { }); }); }); - -httpServer.listen(PORT, HOST, () => { - console.log(`Server running`); -}); \ No newline at end of file diff --git a/traque-front/.gitignore b/traque-front/.gitignore index fd3dbb5..f696615 100644 --- a/traque-front/.gitignore +++ b/traque-front/.gitignore @@ -34,3 +34,5 @@ yarn-error.log* # typescript *.tsbuildinfo next-env.d.ts + +certificates \ No newline at end of file diff --git a/traque-front/components/team/actionDrawer.jsx b/traque-front/components/team/actionDrawer.jsx index e574d65..028aee1 100644 --- a/traque-front/components/team/actionDrawer.jsx +++ b/traque-front/components/team/actionDrawer.jsx @@ -33,7 +33,7 @@ export default function ActionDrawer() {
- { console.log(i) }} /> + { console.log(i) }} /> Capture target
diff --git a/traque-front/components/team/loginForm.jsx b/traque-front/components/team/loginForm.jsx index 0b6276a..044bdbc 100644 --- a/traque-front/components/team/loginForm.jsx +++ b/traque-front/components/team/loginForm.jsx @@ -13,7 +13,7 @@ export default function LoginForm({ onSubmit, title, placeholder, buttonText}) { return (

{title}

- setValue(e.target.value)} name="team-id"/> + setValue(e.target.value)} name="team-id"/> ) diff --git a/traque-front/context/socketContext.jsx b/traque-front/context/socketContext.jsx index f61e488..273c3a5 100644 --- a/traque-front/context/socketContext.jsx +++ b/traque-front/context/socketContext.jsx @@ -3,9 +3,11 @@ import { createContext, useContext, useMemo } from "react"; const { io } = require("socket.io-client"); -const SOCKET_URL = 'http://' + process.env.NEXT_PUBLIC_SOCKET_HOST + ':' + process.env.NEXT_PUBLIC_SOCKET_PORT; +const SOCKET_URL = 'wss://' + process.env.NEXT_PUBLIC_SOCKET_HOST + ':' + process.env.NEXT_PUBLIC_SOCKET_PORT; const USER_SOCKET_URL = SOCKET_URL + "/player"; const ADMIN_SOCKET_URL = SOCKET_URL + "/admin"; +console.log(USER_SOCKET_URL); +console.log(ADMIN_SOCKET_URL); export const teamSocket = io(USER_SOCKET_URL); export const adminSocket = io(ADMIN_SOCKET_URL); diff --git a/traque-front/package.json b/traque-front/package.json index 975cc67..2c2f124 100644 --- a/traque-front/package.json +++ b/traque-front/package.json @@ -4,7 +4,7 @@ "private": true, "author": "Quentin Roussel", "scripts": { - "dev": "next dev", + "dev": "next dev --experimental-https", "build": "next build", "start": "next start", "lint": "next lint"