Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ services:
env_file:
- .env/api
- .env/db
- .env/common
networks:
- app-network

Expand All @@ -43,6 +44,8 @@ services:
restart: always
ports:
- "3000:3000"
env_file:
- .env/common
networks:
- app-network

Expand Down
15 changes: 15 additions & 0 deletions front-js/src/app/api/config/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// import { NextApiRequest, NextApiResponse } from 'next';

// export default function handler(req: NextApiRequest, res: NextApiResponse) {
// res.status(200).json({
// commonKey: process.env.COMMON_KEY
// });
// }

import { NextResponse } from 'next/server';

export async function GET() {
return NextResponse.json({
commonKey: process.env.COMMON_KEY
});
}
9 changes: 8 additions & 1 deletion front-js/src/axiosConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ import axios from "axios";
const instance = axios.create({
baseURL: "http://127.0.0.1:8000/",
headers: {
"X-Common-Key": "79C446ECB8EB7C770E13EAFBF84CC2D6743BDE85AEE2B9CF0818D39D4D4C9467",
"Content-Type": "application/json"
}
});

instance.interceptors.request.use(async (config) => {
const response = await fetch('/api/config');
const { commonKey } = await response.json();

config.headers["X-Common-Key"] = commonKey;
return config;
});

export default instance;
13 changes: 11 additions & 2 deletions SetEnv.py → set_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
ENV_PATH = ".env"
ENV_DB = ENV_PATH + "/db"
ENV_API = ENV_PATH + "/api"
ENV_COMMON = ENV_PATH + "/common"

GREEN = "\x1b[32m"
BLUE = "\x1b[34m"
Expand Down Expand Up @@ -43,6 +44,14 @@ def create_db_env():
f.write("MYSQL_ROOT_PASSWORD=" + passwordroot + "\n")
f.close()

def create_common_env():
"""Create the .env/common file."""
print("Common configuration:")
with open(ENV_COMMON, 'w', encoding="UTF-8") as f:
common_key = input("Common key: ")
f.write("COMMON_KEY=" + common_key + "\n")
f.close()

def create_api_env():
"""Create the .env/api file."""
print("API configuration:")
Expand All @@ -51,8 +60,6 @@ def create_api_env():
f.write("JWT_SECRET_KEY=" + jwt_secret_key + "\n")
jwt_refresh_key = input("JWT Refresh Key: ")
f.write("JWT_REFRESH_KEY=" + jwt_refresh_key + "\n")
common_key = input("Common key: ")
f.write("COMMON_KEY=" + common_key + "\n")
f.close()

if __name__ == "__main__":
Expand All @@ -67,4 +74,6 @@ def create_api_env():
print("")
create_api_env()
print("")
create_common_env()
print("")
print(f"{GREEN}Environment variables set successfully.{RESET}")