Skip to content

Commit

Permalink
backend url on run time
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesbrandenburger committed Jan 17, 2024
1 parent f1ea4d5 commit 2930721
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 21 deletions.
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ services:
environment:
- VITE_TENANT=default
- VITE_TENANT_CLIENT_ID=e9fdb985-9173-4e01-9d73-ac2d60d1dc8e
- VITE_BACKEND_URL=http://localhost/api
frontend-adac:
build:
context: ./frontend
Expand All @@ -40,6 +41,7 @@ services:
environment:
- VITE_TENANT=adac
- VITE_TENANT_CLIENT_ID=74b35a42-b914-4b7e-abb5-c5184a3ca334
- VITE_BACKEND_URL=http://localhost/api
pin-service:
build: ./services/pin-service
ports:
Expand Down
9 changes: 0 additions & 9 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
FROM node:18-alpine

# ARG VITE_TENANT
# ARG VITE_TENANT_CLIENT_ID

# ENV VITE_TENANT=$VITE_TENANT
# ENV VITE_TENANT_CLIENT_ID=$VITE_TENANT_CLIENT_ID

WORKDIR /app

COPY package*.json ./
Expand All @@ -14,9 +8,6 @@ RUN npm ci
COPY . .
RUN npm install serve

# RUN npm run build

EXPOSE 3000
# ENTRYPOINT [ "npx", "serve", "-s" ,"dist" ]

ENTRYPOINT [ "./entrypoint.sh" ]
4 changes: 3 additions & 1 deletion frontend/src/js/tenant.js → frontend/src/js/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-undef */
const BACKEND_URL = import.meta.env.VITE_BACKEND_URL;
const TENANT = import.meta.env.VITE_TENANT;
const TENANT_CLIENT_ID = import.meta.env.VITE_TENANT_CLIENT_ID;
const PATH = TENANT === 'default' ? '' : `/${TENANT}`;
Expand All @@ -10,5 +11,6 @@ console.log(TENANT);
export {
PATH,
TENANT,
TENANT_CLIENT_ID
TENANT_CLIENT_ID,
BACKEND_URL,
};
10 changes: 4 additions & 6 deletions frontend/src/js/requests.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { TENANT } from "./tenant";

const backendUrl = 'http://localhost/api';
import { TENANT, BACKEND_URL } from "./config";

/**
* @param {string} username
*/
export async function getPins() {
try {
const response = await fetch(`${backendUrl}/pin/`, {
const response = await fetch(`${BACKEND_URL}/pin/`, {
method: 'GET',
headers: {
"Content-Type": "application/json",
Expand Down Expand Up @@ -43,7 +41,7 @@ export async function getPins() {
export async function createPin(pin) {
try {
console.log(JSON.stringify(pin));
const response = await fetch(`${backendUrl}/pin/`, {
const response = await fetch(`${BACKEND_URL}/pin/`, {
method: "POST",
body: JSON.stringify(pin),
headers: {
Expand All @@ -67,7 +65,7 @@ export async function createPin(pin) {
*/
export async function getHeatmapData() {
try {
const response = await fetch(`${backendUrl}/heatmap`, {
const response = await fetch(`${BACKEND_URL}/heatmap`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/js/user.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TENANT, TENANT_CLIENT_ID } from "./tenant";
import { TENANT, TENANT_CLIENT_ID } from "./config";

var user = null;

Expand Down
1 change: 0 additions & 1 deletion services/analytics-service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import path from "path";
import { fileURLToPath } from "url";
dotenv.config({ path: path.join(path.dirname(fileURLToPath(import.meta.url)), "../.env") });
const MONDODB_URI = process.env.MONGODB_URI || "mongodb://localhost:27017";
const BACKEND_URL = process.env.BACKEND_URL || "http://localhost";

// connect to MongoDB
const client = new MongoClient(MONDODB_URI);
Expand Down
1 change: 0 additions & 1 deletion services/heatmap-service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import path from "path";
import { fileURLToPath } from "url";
dotenv.config({ path: path.join(path.dirname(fileURLToPath(import.meta.url)), "../.env") });
const MONDODB_URI = process.env.MONGODB_URI || "mongodb://localhost:27017";
const BACKEND_URL = process.env.BACKEND_URL || "http://localhost";

// connect to MongoDB
const client = new MongoClient(MONDODB_URI);
Expand Down
1 change: 0 additions & 1 deletion services/pin-service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import path from "path";
import { fileURLToPath } from "url";
dotenv.config({ path: path.join(path.dirname(fileURLToPath(import.meta.url)), "../.env") });
const MONDODB_URI = process.env.MONGODB_URI || "mongodb://localhost:27017";
const BACKEND_URL = process.env.BACKEND_URL || "http://localhost";

// connect to MongoDB
const client = new MongoClient(MONDODB_URI);
Expand Down
1 change: 0 additions & 1 deletion services/update-service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import path from "path";
import { fileURLToPath } from "url";
dotenv.config({ path: path.join(path.dirname(fileURLToPath(import.meta.url)), "../.env") });
const MONDODB_URI = process.env.MONGODB_URI || "mongodb://localhost:27017";
const BACKEND_URL = process.env.BACKEND_URL || "http://localhost";

// connect to MongoDB
const client = new MongoClient(MONDODB_URI);
Expand Down

0 comments on commit 2930721

Please sign in to comment.