Changement de TOUTES les occurrences d'un host ou d'un port écrits en dur dans le projet.
This commit is contained in:
98
make_env.sh
Normal file → Executable file
98
make_env.sh
Normal file → Executable file
@@ -2,6 +2,11 @@
|
|||||||
|
|
||||||
ENV_FILE_DOCKER=./srcs/.env
|
ENV_FILE_DOCKER=./srcs/.env
|
||||||
ENV_FILE_SVELTE=./srcs/requirements/svelte/api_front/.env
|
ENV_FILE_SVELTE=./srcs/requirements/svelte/api_front/.env
|
||||||
|
NGINX_CONF_FILE=./srcs/requirements/nginx/conf/default.conf
|
||||||
|
BOLD_RED="\033[1;31m"
|
||||||
|
BOLD_GREEN="\033[1;32m"
|
||||||
|
BOLD_BLUE="\033[1;34m"
|
||||||
|
RESET="\033[0m"
|
||||||
|
|
||||||
# Function to generate passwords
|
# Function to generate passwords
|
||||||
#
|
#
|
||||||
@@ -13,6 +18,20 @@ ENV_FILE_SVELTE=./srcs/requirements/svelte/api_front/.env
|
|||||||
echo $(openssl rand -base64 32 | tr "/" "_" );
|
echo $(openssl rand -base64 32 | tr "/" "_" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function make_env_for_svelte
|
||||||
|
{
|
||||||
|
echo -e "${BOLD_BLUE}Creating a new environment for svelte${RESET}"
|
||||||
|
grep "^WEBSITE_" "$ENV_FILE_DOCKER" > "$ENV_FILE_SVELTE"
|
||||||
|
}
|
||||||
|
|
||||||
|
function update_nginx_conf
|
||||||
|
{
|
||||||
|
echo -e "${BOLD_BLUE}Updating the nginx conf${RESET}"
|
||||||
|
echo -e "${BOLD_RED}WARNING : If for some reason you've changed the port, you MUST change it inside the nginx conf file. It's not supposed to change.${RESET}"
|
||||||
|
HOST=$(grep "^WEBSITE_HOST" $ENV_FILE_DOCKER | cut -d "=" -f 2)
|
||||||
|
sed -i "s/server_name.*/server_name $HOST;/g" "$NGINX_CONF_FILE"
|
||||||
|
}
|
||||||
|
|
||||||
function make_env_for_docker_and_svelte
|
function make_env_for_docker_and_svelte
|
||||||
{
|
{
|
||||||
echo "Creating a new environment for docker"
|
echo "Creating a new environment for docker"
|
||||||
@@ -44,36 +63,79 @@ ENV_FILE_SVELTE=./srcs/requirements/svelte/api_front/.env
|
|||||||
echo "FORTYTWO_CLIENT_ID=$CLIENT_ID" >> "$ENV_FILE_DOCKER"
|
echo "FORTYTWO_CLIENT_ID=$CLIENT_ID" >> "$ENV_FILE_DOCKER"
|
||||||
read -p "Enter the client secret of the 42 api : " CLIENT_SECRET
|
read -p "Enter the client secret of the 42 api : " CLIENT_SECRET
|
||||||
echo "FORTYTWO_CLIENT_SECRET=$CLIENT_SECRET" >> "$ENV_FILE_DOCKER"
|
echo "FORTYTWO_CLIENT_SECRET=$CLIENT_SECRET" >> "$ENV_FILE_DOCKER"
|
||||||
FT_CALLBACK="http://\$WEBSITE_HOST:\$WEBSITE_PORT/api/v2/auth/redirect"
|
FT_CALLBACK="http://$PROJECT_HOST:8080/api/v2/auth/redirect"
|
||||||
echo "FORTYTWO_CALLBACK_URL=$FT_CALLBACK" >> "$ENV_FILE_DOCKER"
|
echo "FORTYTWO_CALLBACK_URL=$FT_CALLBACK" >> "$ENV_FILE_DOCKER"
|
||||||
# Other configs
|
# Other configs
|
||||||
echo "COOKIE_SECRET=$(generate_password)" >> "$ENV_FILE_DOCKER"
|
echo "COOKIE_SECRET=$(generate_password)" >> "$ENV_FILE_DOCKER"
|
||||||
echo "PORT=3000" >> "$ENV_FILE_DOCKER"
|
echo "PORT=3000" >> "$ENV_FILE_DOCKER"
|
||||||
echo "TWO_FACTOR_AUTHENTICATION_APP_NAME=Transcendance" >> "$ENV_FILE_DOCKER"
|
echo "TWO_FACTOR_AUTHENTICATION_APP_NAME=Transcendance" >> "$ENV_FILE_DOCKER"
|
||||||
echo "TICKET_FOR_PLAYING_GAME_SECRET=$(generate_password)" >> "$ENV_FILE_DOCKER"
|
echo "TICKET_FOR_PLAYING_GAME_SECRET=$(generate_password)" >> "$ENV_FILE_DOCKER"
|
||||||
grep "WEBSITE_" > "$ENV_FILE_SVELTE"
|
make_env_for_svelte
|
||||||
|
update_nginx_conf
|
||||||
|
echo -e "${BOLD_GREEN}Environment created.${RESET}"
|
||||||
|
echo -e "${BOLD_GREEN}The script will exit${RESET}"
|
||||||
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
function choose_options_and_process {
|
function change_host_and_port_api
|
||||||
if [ -f "$ENV_FILE_DOCKER" ]; then
|
{
|
||||||
echo "The file $ENV_FILE_DOCKER already exists. Do you want to overwrite it ? (y/n)"
|
if [ -f "$ENV_FILE_DOCKER" ]
|
||||||
OVERWRITE=""
|
then
|
||||||
# Ask to overwrite the .env files
|
echo -e "${BOLD_BLUE}Changing the host and the port of the api${RESET}"
|
||||||
while [ "$OVERWRITE" != "y" ] && [ "$OVERWRITE" != "n" ]; do
|
read -p "Enter the name of the host like \"localhost\" : " PROJECT_HOST
|
||||||
read -p "Enter your choice : " OVERWRITE
|
sed -i "s/WEBSITE_HOST=.*/WEBSITE_HOST=$PROJECT_HOST/g" "$ENV_FILE_DOCKER"
|
||||||
done
|
read -p "Enter the port of the api : " PROJECT_PORT
|
||||||
if [ "$OVERWRITE" = "y" ]; then
|
sed -i "s/WEBSITE_PORT=.*/WEBSITE_PORT=$PROJECT_PORT/g" "$ENV_FILE_DOCKER"
|
||||||
rm "$ENV_FILE_DOCKER" && rm "$ENV_FILE_SVELTE"
|
make_env_for_svelte
|
||||||
docker rmi -f postgres
|
update_nginx_conf
|
||||||
make_env_for_docker_and_svelte
|
|
||||||
else
|
else
|
||||||
if [ ! -f "$ENV_FILE_SVELTE" ]; then
|
echo -e "${BOLD_RED}No environment file found. We will regenerate the entire env files.${RESET}"
|
||||||
grep "WEBSITE_" > "$ENV_FILE_SVELTE"
|
|
||||||
fi
|
fi
|
||||||
echo "The file $ENV_FILE_DOCKER will not be overwritten. The script will exit."
|
}
|
||||||
|
|
||||||
|
function change_api_fields_for_42_auth_api
|
||||||
|
{
|
||||||
|
if [ -f "$ENV_FILE_DOCKER" ]
|
||||||
|
then
|
||||||
|
echo -e "${BOLD_BLUE}Changing the secret for the 42 api${RESET}"
|
||||||
|
read -p "Enter the client id of the 42 api : " CLIENT_ID
|
||||||
|
sed -i "s/FORTYTWO_CLIENT_ID=.*/FORTYTWO_CLIENT_ID=$CLIENT_ID/g" "$ENV_FILE_DOCKER"
|
||||||
|
read -p "Enter the client secret of the 42 api : " CLIENT_SECRET
|
||||||
|
sed -i "s/FORTYTWO_CLIENT_SECRET=.*/FORTYTWO_CLIENT_SECRET=$CLIENT_SECRET/g" "$ENV_FILE_DOCKER"
|
||||||
|
echo -e "${BOLD_GREEN}The fields concerning the 42 api have been changed.${RESET}"
|
||||||
|
else
|
||||||
|
echo -e "${BOLD_RED}No environment file found. We will regenerate the entire env files.${RESET}"
|
||||||
|
make_env_for_docker_and_svelte
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function choose_options_and_process {
|
||||||
|
if [ ! -f "$ENV_FILE_DOCKER" ]; then
|
||||||
|
make_env_for_docker_and_svelte
|
||||||
|
elif [ ! -f "$ENV_FILE_SVELTE" && -f "$ENV_FILE_DOCKER" ]; then
|
||||||
|
make_env_for_svelte
|
||||||
|
fi
|
||||||
|
echo -e "${BOLD_RED}An environment already exists.${RESET}"
|
||||||
|
echo -e "${BOLD_GREEN}What do you want to do ?${RESET}"
|
||||||
|
echo -e "${BOLD_GREEN}1. Regenerate entire environment${RESET}"
|
||||||
|
echo -e "${BOLD_GREEN}2. Only change the fields about the HOSTNAME and the PORT of the API${RESET}"
|
||||||
|
echo -e "${BOLD_GREEN}3. Only change the fields concerning the 42 API (id and secret)${RESET}"
|
||||||
|
echo -e "${BOLD_GREEN}4. Exit${RESET}"
|
||||||
|
CHOICE=""
|
||||||
|
while [ "$CHOICE" != "1" ] && [ "$CHOICE" != "2" ] && [ "$CHOICE" != "3" ] && [ "$CHOICE" != "4" ]; do
|
||||||
|
read -p "Enter your choice : " CHOICE
|
||||||
|
done
|
||||||
|
if [ "$CHOICE" = "1" ]; then
|
||||||
|
make_env_for_docker_and_svelte
|
||||||
|
elif [ "$CHOICE" = "2" ]; then
|
||||||
|
change_host_and_port_api
|
||||||
|
elif [ "$CHOICE" = "3" ]; then
|
||||||
|
change_api_fields_for_42_auth_api
|
||||||
|
else
|
||||||
|
echo -e "${BOLD_GREEN}The script will exit.${RESET}"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
# Create a new environment for docker
|
# Create a new environment for docker
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ services:
|
|||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
environment:
|
environment:
|
||||||
NODE_ENV: "${NODE_ENV}"
|
NODE_ENV: "${NODE_ENV}"
|
||||||
|
WEBSITE_HOST: "${WEBSITE_HOST}"
|
||||||
|
WEBSITE_PORT: "${WEBSITE_PORT}"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- "8042:8042"
|
- "8042:8042"
|
||||||
|
|||||||
@@ -37,10 +37,10 @@ export class AuthenticationController {
|
|||||||
const user : User = request.user
|
const user : User = request.user
|
||||||
if (user.isEnabledTwoFactorAuth === false || user.isTwoFactorAuthenticated === true){
|
if (user.isEnabledTwoFactorAuth === false || user.isTwoFactorAuthenticated === true){
|
||||||
console.log('ON VA VERS PROFILE');
|
console.log('ON VA VERS PROFILE');
|
||||||
return response.status(200).redirect('http://transcendance:8080/#/profile');
|
return response.status(200).redirect('http://' + process.env.WEBSITE_HOST + ':' + process.env.WEBSITE_PORT + '/#/profile');
|
||||||
}
|
}
|
||||||
console.log('ON VA VERS 2FA')
|
console.log('ON VA VERS 2FA')
|
||||||
return response.status(200).redirect('http://transcendance:8080/#/2fa');
|
return response.status(200).redirect('http://' + process.env.WEBSITE_HOST + ':' + process.env.WEBSITE_PORT + '/#/2fa');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,6 +83,6 @@ export class AuthenticationController {
|
|||||||
throw new UnauthorizedException('Wrong Code.');
|
throw new UnauthorizedException('Wrong Code.');
|
||||||
await this.userService.authenticateUserWith2FA(request.user.id);
|
await this.userService.authenticateUserWith2FA(request.user.id);
|
||||||
console.log('ON REDIRIGE');
|
console.log('ON REDIRIGE');
|
||||||
return response.status(200).redirect('http://transcendance:8080/#/profile');
|
return response.status(200).redirect('http://' + process.env.WEBSITE_HOST + ':' + process.env.WEBSITE_PORT + '/#/profile');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
server {
|
server {
|
||||||
|
listen 8080;
|
||||||
listen 8080 default_server;
|
listen [::]:8080;
|
||||||
listen [::]:8080 default_server;
|
server_name localhost;
|
||||||
server_name transcendance;
|
|
||||||
|
|
||||||
location /api/v2 {
|
location /api/v2 {
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
@@ -17,7 +16,7 @@ server {
|
|||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
proxy_set_header Connection "upgrade";
|
proxy_set_header Connection "Upgrade";
|
||||||
proxy_pass http://backend_dev:5000/chat;
|
proxy_pass http://backend_dev:5000/chat;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,10 +42,9 @@ server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
server {
|
server {
|
||||||
|
|
||||||
listen 35729 default_server;
|
listen 35729 default_server;
|
||||||
listen [::]:35729 default_server;
|
listen [::]:35729 default_server;
|
||||||
server_name transcendance;
|
server_name localhost;
|
||||||
location / {
|
location / {
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ import * as c from "./constants.js"
|
|||||||
|
|
||||||
// export const soundPongArr: HTMLAudioElement[] = [];
|
// export const soundPongArr: HTMLAudioElement[] = [];
|
||||||
export const soundPongArr: HTMLAudioElement[] = [
|
export const soundPongArr: HTMLAudioElement[] = [
|
||||||
new Audio("http://transcendance:8080/sound/pong/"+1+".ogg"),
|
new Audio("http://" + process.env.WEBSITE_HOST + ":" + process.env.WEBSITE_PORT + "/sound/pong/"+1+".ogg"),
|
||||||
new Audio("http://transcendance:8080/sound/pong/"+2+".ogg")
|
new Audio("http://" + process.env.WEBSITE_HOST + ":" + process.env.WEBSITE_PORT + "/sound/pong/"+2+".ogg")
|
||||||
];
|
];
|
||||||
export const soundRoblox = new Audio("http://transcendance:8080/sound/roblox-oof.ogg");
|
export const soundRoblox = new Audio("http://" + process.env.WEBSITE_HOST + ":" + process.env.WEBSITE_PORT + "/sound/roblox-oof.ogg");
|
||||||
|
|
||||||
export function initAudio(sound: string)
|
export function initAudio(sound: string)
|
||||||
{
|
{
|
||||||
@@ -18,11 +18,6 @@ export function initAudio(sound: string)
|
|||||||
muteFlag = true;
|
muteFlag = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* for (let i = 0; i <= 32; i++) {
|
|
||||||
soundPongArr.push(new Audio("http://transcendance:8080/sound/pong/"+i+".ogg"));
|
|
||||||
soundPongArr[i].volume = c.soundPongVolume;
|
|
||||||
soundPongArr[i].muted = muteFlag;
|
|
||||||
} */
|
|
||||||
soundPongArr.forEach((value) => {
|
soundPongArr.forEach((value) => {
|
||||||
value.volume = c.soundRobloxVolume;
|
value.volume = c.soundRobloxVolume;
|
||||||
value.muted = muteFlag;
|
value.muted = muteFlag;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class ClientInfoSpectator {
|
|||||||
playerRightNextPos: VectorInteger;
|
playerRightNextPos: VectorInteger;
|
||||||
}
|
}
|
||||||
|
|
||||||
const wsUrl = "ws://transcendance:8080/pong";
|
const wsUrl = "ws://" + process.env.WEBSITE_HOST + ":" + process.env.WEBSITE_PORT + "/pong";
|
||||||
export let socket: WebSocket; /* TODO: A way to still use "const" not "let" ? */
|
export let socket: WebSocket; /* TODO: A way to still use "const" not "let" ? */
|
||||||
export const clientInfo = new ClientInfo();
|
export const clientInfo = new ClientInfo();
|
||||||
export const clientInfoSpectator = new ClientInfoSpectator(); // WIP, could refactor this
|
export const clientInfoSpectator = new ClientInfoSpectator(); // WIP, could refactor this
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export const primaryRoutes = {
|
|||||||
component: ProfilePage,
|
component: ProfilePage,
|
||||||
conditions: [
|
conditions: [
|
||||||
async(detail) => {
|
async(detail) => {
|
||||||
const user = await fetch('http://transcendance:8080/api/v2/user')
|
const user = await fetch('http://' + process.env.WEBSITE_HOST + ":" + process.env.WEBSITE_PORT + '/api/v2/user')
|
||||||
.then((resp) => resp.json())
|
.then((resp) => resp.json())
|
||||||
|
|
||||||
console.log('in /profile what is in user')
|
console.log('in /profile what is in user')
|
||||||
@@ -38,7 +38,7 @@ export const primaryRoutes = {
|
|||||||
component: ProfilePage,
|
component: ProfilePage,
|
||||||
conditions: [
|
conditions: [
|
||||||
async(detail) => {
|
async(detail) => {
|
||||||
const user = await fetch('http://transcendance:8080/api/v2/user')
|
const user = await fetch('http://' + process.env.WEBSITE_HOST + ":" + process.env.WEBSITE_PORT + '/api/v2/user')
|
||||||
.then((resp) => resp.json())
|
.then((resp) => resp.json())
|
||||||
|
|
||||||
console.log('in /profile/* what is in user')
|
console.log('in /profile/* what is in user')
|
||||||
|
|||||||
Reference in New Issue
Block a user