Updated axios request object, added minio
This commit is contained in:
@@ -17,6 +17,12 @@ REFRESH_TOKEN_MAXAGE=30
|
|||||||
REDIS_HOST=localhost
|
REDIS_HOST=localhost
|
||||||
REDIS_PORT=6379
|
REDIS_PORT=6379
|
||||||
|
|
||||||
|
MINIO_ROOT_USER=siren
|
||||||
|
MINIO_ROOT_PASSWORD=
|
||||||
|
MINIO_HOST=localhost
|
||||||
|
MINIO_PORT=9000
|
||||||
|
MINIO_PORT_INTERNAL=9001
|
||||||
|
|
||||||
SERVICE_HOST=localhost
|
SERVICE_HOST=localhost
|
||||||
SERVICE_PORT=5000
|
SERVICE_PORT=5000
|
||||||
DATA_DIR_PATH=
|
DATA_DIR_PATH=
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ argon2 = "0.5.2"
|
|||||||
jsonwebtoken = "9.0.0"
|
jsonwebtoken = "9.0.0"
|
||||||
redis = { version = "0.23.3", features = ["tokio-comp", "connection-manager", "r2d2"] }
|
redis = { version = "0.23.3", features = ["tokio-comp", "connection-manager", "r2d2"] }
|
||||||
base64 = "0.21.4"
|
base64 = "0.21.4"
|
||||||
|
rust-s3 = "0.33.0"
|
||||||
|
|
||||||
[dependencies.tokio]
|
[dependencies.tokio]
|
||||||
version = "1.32.0"
|
version = "1.32.0"
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ build: ## Build the docker image
|
|||||||
utils: ## Start the utils
|
utils: ## Start the utils
|
||||||
docker compose up -d db
|
docker compose up -d db
|
||||||
docker compose up -d redis
|
docker compose up -d redis
|
||||||
|
docker compose up -d minio
|
||||||
|
|
||||||
up: ## Start the app
|
up: ## Start the app
|
||||||
docker compose up -d
|
docker compose up -d
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
version: '3.8'
|
version: '3.8'
|
||||||
|
|
||||||
|
x-env_file_personifi: &env
|
||||||
|
- .env
|
||||||
|
|
||||||
name: siren
|
name: siren
|
||||||
services:
|
services:
|
||||||
service:
|
service:
|
||||||
@@ -10,13 +13,14 @@ services:
|
|||||||
dockerfile: ./Dockerfile
|
dockerfile: ./Dockerfile
|
||||||
args:
|
args:
|
||||||
- VERSION=${SIREN_VERSION:-latest}
|
- VERSION=${SIREN_VERSION:-latest}
|
||||||
env_file:
|
env_file: *env
|
||||||
- .env
|
|
||||||
environment:
|
environment:
|
||||||
DATABASE_HOST: db
|
DATABASE_HOST: db
|
||||||
DATABASE_PORT: 5432
|
DATABASE_PORT: 5432
|
||||||
REDIS_HOST: redis
|
REDIS_HOST: redis
|
||||||
REDIS_PORT: 6379
|
REDIS_PORT: 6379
|
||||||
|
MINIO_HOST: minio
|
||||||
|
MINIO_PORT: 9000
|
||||||
SERVICE_HOST: service
|
SERVICE_HOST: service
|
||||||
SERVICE_PORT: 5000
|
SERVICE_PORT: 5000
|
||||||
DATA_DIR_PATH: /data
|
DATA_DIR_PATH: /data
|
||||||
@@ -33,8 +37,7 @@ services:
|
|||||||
db:
|
db:
|
||||||
image: postgres:latest
|
image: postgres:latest
|
||||||
container_name: siren-db
|
container_name: siren-db
|
||||||
env_file:
|
env_file: *env
|
||||||
- .env
|
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_USER: ${DATABASE_USER}
|
POSTGRES_USER: ${DATABASE_USER}
|
||||||
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
|
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
|
||||||
@@ -55,10 +58,26 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
- backend
|
- backend
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
minio:
|
||||||
|
image: minio/minio
|
||||||
|
container_name: siren-minio
|
||||||
|
environment:
|
||||||
|
MINIO_ROOT_USER: ${MINIO_ROOT_USER}
|
||||||
|
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}
|
||||||
|
volumes:
|
||||||
|
- minio:/data
|
||||||
|
ports:
|
||||||
|
- ${MINIO_PORT:-9000}:9000
|
||||||
|
- ${MINIO_PORT_INTERNAL:-9001}:9001
|
||||||
|
networks:
|
||||||
|
- backend
|
||||||
|
command: server --console-address ":9001" /data
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
db:
|
db:
|
||||||
db_logs:
|
db_logs:
|
||||||
|
minio:
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
frontend:
|
frontend:
|
||||||
|
|||||||
@@ -98,11 +98,13 @@ async fn login(request: web::Json<LoginRequest>) -> HttpResponse {
|
|||||||
.path("/")
|
.path("/")
|
||||||
.max_age(Duration::new(access_token_max_age * 60, 0))
|
.max_age(Duration::new(access_token_max_age * 60, 0))
|
||||||
.http_only(true)
|
.http_only(true)
|
||||||
|
.secure(true)
|
||||||
.finish();
|
.finish();
|
||||||
let refresh_cookie = Cookie::build("refresh_token", refresh_token_details.token.clone().unwrap())
|
let refresh_cookie = Cookie::build("refresh_token", refresh_token_details.token.clone().unwrap())
|
||||||
.path("/")
|
.path("/")
|
||||||
.max_age(Duration::new(refresh_token_max_age * 60, 0))
|
.max_age(Duration::new(refresh_token_max_age * 60, 0))
|
||||||
.http_only(true)
|
.http_only(true)
|
||||||
|
.secure(true)
|
||||||
.finish();
|
.finish();
|
||||||
let logged_in_cookie = Cookie::build("logged_in", "true")
|
let logged_in_cookie = Cookie::build("logged_in", "true")
|
||||||
.path("/")
|
.path("/")
|
||||||
@@ -210,6 +212,7 @@ async fn refresh(req: HttpRequest) -> HttpResponse {
|
|||||||
.path("/")
|
.path("/")
|
||||||
.max_age(Duration::new(access_token_max_age * 60, 0))
|
.max_age(Duration::new(access_token_max_age * 60, 0))
|
||||||
.http_only(true)
|
.http_only(true)
|
||||||
|
.secure(true)
|
||||||
.finish();
|
.finish();
|
||||||
let logged_in_cookie = Cookie::build("logged_in", "true")
|
let logged_in_cookie = Cookie::build("logged_in", "true")
|
||||||
.path("/")
|
.path("/")
|
||||||
@@ -254,6 +257,7 @@ async fn refresh(req: HttpRequest) -> HttpResponse {
|
|||||||
.path("/")
|
.path("/")
|
||||||
.max_age(Duration::new(refresh_token_max_age * 60, 0))
|
.max_age(Duration::new(refresh_token_max_age * 60, 0))
|
||||||
.http_only(true)
|
.http_only(true)
|
||||||
|
.secure(true)
|
||||||
.finish();
|
.finish();
|
||||||
|
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
- NODE_ENV=${NODE_ENV:-development}
|
- NODE_ENV=${NODE_ENV:-development}
|
||||||
ports:
|
ports:
|
||||||
- ${UI_PORT:-8080}:3000
|
- ${UI_PORT:-3000}:3000
|
||||||
build:
|
build:
|
||||||
context: ./
|
context: ./
|
||||||
target: dev
|
target: dev
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { getRequest, postRequest } from '.';
|
|||||||
import { RegisterUser, ResponseAuth } from './auth.types';
|
import { RegisterUser, ResponseAuth } from './auth.types';
|
||||||
|
|
||||||
export async function login(email: string, password: string): Promise<ResponseAuth | undefined> {
|
export async function login(email: string, password: string): Promise<ResponseAuth | undefined> {
|
||||||
const response = await postRequest('auth/login', { email, password }, { withCredentials: true });
|
const response = await postRequest('auth/login', { email, password });
|
||||||
if (response?.status === 200) {
|
if (response?.status === 200) {
|
||||||
return response.data as ResponseAuth;
|
return response.data as ResponseAuth;
|
||||||
} else {
|
} else {
|
||||||
@@ -11,7 +11,7 @@ export async function login(email: string, password: string): Promise<ResponseAu
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function register(user: RegisterUser): Promise<boolean> {
|
export async function register(user: RegisterUser): Promise<boolean> {
|
||||||
const response = await postRequest('auth/register', user, { withCredentials: true });
|
const response = await postRequest('auth/register', user);
|
||||||
if (response?.status === 201) {
|
if (response?.status === 201) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@@ -20,11 +20,11 @@ export async function register(user: RegisterUser): Promise<boolean> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function logout() {
|
export async function logout() {
|
||||||
return await postRequest('auth/logout', {}, { withCredentials: true });
|
return await postRequest('auth/logout', {});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function refresh(refresh_token_rotation?: boolean): Promise<ResponseAuth | undefined> {
|
export async function refresh(refresh_token_rotation?: boolean): Promise<ResponseAuth | undefined> {
|
||||||
const response = await getRequest('auth/refresh', { withCredentials: true, params: { refresh_token_rotation } });
|
const response = await getRequest('auth/refresh', { params: { refresh_token_rotation } });
|
||||||
if (response?.status === 200) {
|
if (response?.status === 200) {
|
||||||
return response.data as ResponseAuth;
|
return response.data as ResponseAuth;
|
||||||
} else {
|
} else {
|
||||||
@@ -33,7 +33,7 @@ export async function refresh(refresh_token_rotation?: boolean): Promise<Respons
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function me(): Promise<ResponseAuth | undefined> {
|
export async function me(): Promise<ResponseAuth | undefined> {
|
||||||
const response = await getRequest('auth/me', { withCredentials: true });
|
const response = await getRequest('auth/me');
|
||||||
if (response?.status === 200) {
|
if (response?.status === 200) {
|
||||||
return response.data;
|
return response.data;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,15 +1,33 @@
|
|||||||
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
|
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
||||||
|
|
||||||
const serviceHost = process.env.SERVICE_HOST || 'http://localhost';
|
const serviceHost = process.env.SERVICE_HOST || 'http://localhost';
|
||||||
const servicePort = process.env.SERVICE_PORT || 5000;
|
const servicePort = process.env.SERVICE_PORT || 5000;
|
||||||
|
|
||||||
|
function createAxiosClient(): AxiosInstance {
|
||||||
|
const axiosClient = axios.create({
|
||||||
|
baseURL: `${serviceHost}:${servicePort}`
|
||||||
|
});
|
||||||
|
|
||||||
|
axiosClient.interceptors.request.use(
|
||||||
|
(request) => {
|
||||||
|
request.withCredentials = true;
|
||||||
|
return request;
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
console.error(error);
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return axiosClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
const axiosClient = createAxiosClient();
|
||||||
|
|
||||||
export async function getRequest(
|
export async function getRequest(
|
||||||
url: string,
|
url: string,
|
||||||
config?: AxiosRequestConfig<any>
|
config?: AxiosRequestConfig<any>
|
||||||
): Promise<AxiosResponse<any, any> | undefined> {
|
): Promise<AxiosResponse<any, any> | undefined> {
|
||||||
const response = await axios
|
const response = await axiosClient.get(`/${url}`, config);
|
||||||
.get(`${serviceHost}:${servicePort}/${url}`, config)
|
|
||||||
.catch((error) => console.error(error));
|
|
||||||
return response || undefined;
|
return response || undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,9 +36,7 @@ export async function postRequest(
|
|||||||
data?: any,
|
data?: any,
|
||||||
config?: AxiosRequestConfig<any>
|
config?: AxiosRequestConfig<any>
|
||||||
): Promise<AxiosResponse<any, any> | undefined> {
|
): Promise<AxiosResponse<any, any> | undefined> {
|
||||||
const response = await axios
|
const response = await axiosClient.post(`/${url}`, data, config);
|
||||||
.post(`${serviceHost}:${servicePort}/${url}`, data, config)
|
|
||||||
.catch((error) => console.error(error));
|
|
||||||
return response || undefined;
|
return response || undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ export default function Topbar() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, []);
|
}, [pathName]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const h: HeaderItem[] = [];
|
const h: HeaderItem[] = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user