mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-02-09 02:10:18 +01:00
deploiement: reverse proxy nginx pour rediriger les requetes au front ou back suivant url
This commit is contained in:
@@ -1,19 +1,18 @@
|
|||||||
services:
|
services:
|
||||||
front:
|
reverse_proxy:
|
||||||
|
build: ./proxy
|
||||||
ports:
|
ports:
|
||||||
- "3000:3000"
|
- "80:80"
|
||||||
|
restart: always
|
||||||
|
|
||||||
|
front:
|
||||||
build: ./traque-front
|
build: ./traque-front
|
||||||
restart: always
|
restart: always
|
||||||
|
|
||||||
back:
|
back:
|
||||||
build: ./traque-back
|
build: ./traque-back
|
||||||
ports:
|
|
||||||
- "3001:3001"
|
|
||||||
restart: always
|
restart: always
|
||||||
environment:
|
environment:
|
||||||
ADMIN_PASSWORD: 'traquebdsbanger'
|
ADMIN_PASSWORD: 'traquebdsbanger'
|
||||||
HOST: '0.0.0.0'
|
HOST: '0.0.0.0'
|
||||||
PORT: 3001
|
PORT: 3001
|
||||||
#Those files need to exist in traque-back/ssl for https to work
|
|
||||||
SSL_KEY: "ssl/privkey.pem"
|
|
||||||
SSL_CERT: "ssl/cert.pem"
|
|
||||||
7
proxy/Dockerfile
Normal file
7
proxy/Dockerfile
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# nginx/Dockerfile
|
||||||
|
|
||||||
|
FROM nginx:alpine
|
||||||
|
|
||||||
|
COPY nginx.conf /etc/nginx/nginx.conf
|
||||||
|
|
||||||
|
EXPOSE 80
|
||||||
26
proxy/nginx.conf
Normal file
26
proxy/nginx.conf
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
# nginx/nginx.conf
|
||||||
|
events {
|
||||||
|
worker_connections 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
http {
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
location / {
|
||||||
|
proxy_pass http://front:3000/;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /back/ {
|
||||||
|
proxy_pass http://back:3001/;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "Upgrade";
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { createServer } from "https";
|
import { createServer } from "http";
|
||||||
import express from "express";
|
import express from "express";
|
||||||
|
|
||||||
import { Server } from "socket.io";
|
import { Server } from "socket.io";
|
||||||
@@ -14,19 +14,16 @@ const PORT = process.env.PORT;
|
|||||||
|
|
||||||
export const app = express()
|
export const app = express()
|
||||||
|
|
||||||
const httpsServer = createServer({
|
const httpServer = createServer({}, app);
|
||||||
key: readFileSync(process.env.SSL_KEY, 'utf-8'),
|
|
||||||
cert: readFileSync(process.env.SSL_CERT, 'utf-8')
|
|
||||||
}, app);
|
|
||||||
|
|
||||||
httpsServer.listen(PORT, HOST, () => {
|
httpServer.listen(PORT, HOST, () => {
|
||||||
console.log(`Server running`);
|
console.log("Server running on http://" + HOST + ":" + PORT);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//set cors to allow all origins
|
//set cors to allow all origins
|
||||||
export const io = new Server(httpsServer, {
|
export const io = new Server(httpServer, {
|
||||||
cors: {
|
cors: {
|
||||||
origin: "*",
|
origin: "*",
|
||||||
methods: ["GET", "POST"]
|
methods: ["GET", "POST"]
|
||||||
@@ -35,4 +32,4 @@ export const io = new Server(httpsServer, {
|
|||||||
|
|
||||||
initAdminSocketHandler();
|
initAdminSocketHandler();
|
||||||
initTeamSocket();
|
initTeamSocket();
|
||||||
initPhotoUpload();
|
initPhotoUpload();
|
||||||
|
|||||||
@@ -12,8 +12,13 @@ export default function TeamEdit({ selectedTeamId, setSelectedTeamId }) {
|
|||||||
const teamImage = useRef(null);
|
const teamImage = useRef(null);
|
||||||
const [newTeamName, setNewTeamName] = React.useState('');
|
const [newTeamName, setNewTeamName] = React.useState('');
|
||||||
const { updateTeam, getTeamName, removeTeam, getTeam, teams } = useAdmin();
|
const { updateTeam, getTeamName, removeTeam, getTeam, teams } = useAdmin();
|
||||||
const [team, setTeam] = useState({})
|
const [team, setTeam] = useState({});
|
||||||
const SERVER_URL = "https://" + process.env.NEXT_PUBLIC_SOCKET_HOST + ":" + process.env.NEXT_PUBLIC_SOCKET_PORT;
|
var protocol = "https://";
|
||||||
|
if (process.env.NEXT_PUBLIC_SOCKET_HOST == "localhost") {
|
||||||
|
protocol = "http://";
|
||||||
|
}
|
||||||
|
const SERVER_URL = protocol + process.env.NEXT_PUBLIC_SOCKET_HOST + "/back";
|
||||||
|
console.log(SERVER_URL);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let team = getTeam(selectedTeamId);
|
let team = getTeam(selectedTeamId);
|
||||||
|
|||||||
@@ -17,7 +17,12 @@ export function EnemyTeamModal({ visible, onClose }) {
|
|||||||
imageRef.current.src = SERVER_URL + "/photo/enemy?team=" + teamId.toString() + "&t=" + new Date().getTime();
|
imageRef.current.src = SERVER_URL + "/photo/enemy?team=" + teamId.toString() + "&t=" + new Date().getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
const SERVER_URL = "https://" + process.env.NEXT_PUBLIC_SOCKET_HOST + ":" + process.env.NEXT_PUBLIC_SOCKET_PORT;
|
var protocol = "https://";
|
||||||
|
if (process.env.NEXT_PUBLIC_SOCKET_HOST == "localhost") {
|
||||||
|
protocol = "http://";
|
||||||
|
}
|
||||||
|
const SERVER_URL = protocol + process.env.NEXT_PUBLIC_SOCKET_HOST + "/back";
|
||||||
|
console.log(SERVER_URL);
|
||||||
return (visible &&
|
return (visible &&
|
||||||
<>
|
<>
|
||||||
<div className='fixed w-screen h-screen bg-black bg-opacity-50 z-10 text-center'></div>
|
<div className='fixed w-screen h-screen bg-black bg-opacity-50 z-10 text-center'></div>
|
||||||
|
|||||||
@@ -8,7 +8,12 @@ export function WaitingScreen() {
|
|||||||
const { name, teamId } = useGame();
|
const { name, teamId } = useGame();
|
||||||
const { gameSettings } = useTeamContext();
|
const { gameSettings } = useTeamContext();
|
||||||
const imageRef = useRef(null);
|
const imageRef = useRef(null);
|
||||||
const SERVER_URL = "https://" + process.env.NEXT_PUBLIC_SOCKET_HOST + ":" + process.env.NEXT_PUBLIC_SOCKET_PORT;
|
var protocol = "https://";
|
||||||
|
if (process.env.NEXT_PUBLIC_SOCKET_HOST == "localhost") {
|
||||||
|
protocol = "http://";
|
||||||
|
}
|
||||||
|
const SERVER_URL = protocol + process.env.NEXT_PUBLIC_SOCKET_HOST + "/back";
|
||||||
|
console.log(SERVER_URL);
|
||||||
|
|
||||||
function sendImage() {
|
function sendImage() {
|
||||||
let data = new FormData();
|
let data = new FormData();
|
||||||
|
|||||||
@@ -3,12 +3,21 @@ import { createContext, useContext, useMemo } from "react";
|
|||||||
|
|
||||||
const { io } = require("socket.io-client");
|
const { io } = require("socket.io-client");
|
||||||
|
|
||||||
const SOCKET_URL = 'wss://' + process.env.NEXT_PUBLIC_SOCKET_HOST + ':' + process.env.NEXT_PUBLIC_SOCKET_PORT;
|
var proto = "wss://";
|
||||||
|
if (process.env.NEXT_PUBLIC_SOCKET_HOST == "localhost") {
|
||||||
|
proto = "ws://";
|
||||||
|
}
|
||||||
|
const SOCKET_URL = proto + process.env.NEXT_PUBLIC_SOCKET_HOST;
|
||||||
const USER_SOCKET_URL = SOCKET_URL + "/player";
|
const USER_SOCKET_URL = SOCKET_URL + "/player";
|
||||||
const ADMIN_SOCKET_URL = SOCKET_URL + "/admin";
|
const ADMIN_SOCKET_URL = SOCKET_URL + "/admin";
|
||||||
|
|
||||||
export const teamSocket = io(USER_SOCKET_URL);
|
export const teamSocket = io(USER_SOCKET_URL, {
|
||||||
export const adminSocket = io(ADMIN_SOCKET_URL);
|
path: "/back/socket.io",
|
||||||
|
});
|
||||||
|
export const adminSocket = io(ADMIN_SOCKET_URL, {
|
||||||
|
path: "/back/socket.io",
|
||||||
|
});
|
||||||
|
|
||||||
export const SocketContext = createContext();
|
export const SocketContext = createContext();
|
||||||
|
|
||||||
export default function SocketProvider({ children }) {
|
export default function SocketProvider({ children }) {
|
||||||
|
|||||||
Reference in New Issue
Block a user