mirror of
https://github.com/nikdoof/pocket-id.git
synced 2025-12-14 07:12:19 +00:00
feat: add INTERNAL_BACKEND_URL env variable
This commit is contained in:
15
README.md
15
README.md
@@ -137,13 +137,14 @@ docker compose up -d
|
|||||||
|
|
||||||
### Environment variables
|
### Environment variables
|
||||||
|
|
||||||
| Variable | Default Value | Recommended to change | Description |
|
| Variable | Default Value | Recommended to change | Description |
|
||||||
| ---------------- | ------------------- | --------------------- | --------------------------------------------- |
|
| ---------------------- | ----------------------- | --------------------- | --------------------------------------------- |
|
||||||
| `PUBLIC_APP_URL` | `http://localhost` | yes | The URL where you will access the app. |
|
| `PUBLIC_APP_URL` | `http://localhost` | yes | The URL where you will access the app. |
|
||||||
| `DB_PATH` | `data/pocket-id.db` | no | The path to the SQLite database. |
|
| `DB_PATH` | `data/pocket-id.db` | no | The path to the SQLite database. |
|
||||||
| `UPLOAD_PATH` | `data/uploads` | no | The path where the uploaded files are stored. |
|
| `UPLOAD_PATH` | `data/uploads` | no | The path where the uploaded files are stored. |
|
||||||
| `PORT` | `3000` | no | The port on which the frontend should listen. |
|
| `INTERNAL_BACKEND_URL` | `http://localhost:8080` | no | The URL where the backend is accessible. |
|
||||||
| `BACKEND_PORT` | `8080` | no | The port on which the backend should listen. |
|
| `PORT` | `3000` | no | The port on which the frontend should listen. |
|
||||||
|
| `BACKEND_PORT` | `8080` | no | The port on which the backend should listen. |
|
||||||
|
|
||||||
## Contribute
|
## Contribute
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
PUBLIC_APP_URL=http://localhost
|
PUBLIC_APP_URL=http://localhost
|
||||||
|
INTERNAL_BACKEND_URL=http://localhost:8080
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
|
import { env } from '$env/dynamic/private';
|
||||||
import type { Handle, HandleServerError } from '@sveltejs/kit';
|
import type { Handle, HandleServerError } from '@sveltejs/kit';
|
||||||
import { AxiosError } from 'axios';
|
import { AxiosError } from 'axios';
|
||||||
import jwt from 'jsonwebtoken';
|
import jwt from 'jsonwebtoken';
|
||||||
|
|
||||||
|
// Workaround so that we can also import this environment variable into client-side code
|
||||||
|
// If we would directly import $env/dynamic/private into the api-service.ts file, it would throw an error
|
||||||
|
// this is still secure as process will just be undefined in the browser
|
||||||
|
process.env.INTERNAL_BACKEND_URL = env.INTERNAL_BACKEND_URL ?? 'http://localhost:8080';
|
||||||
|
|
||||||
export const handle: Handle = async ({ event, resolve }) => {
|
export const handle: Handle = async ({ event, resolve }) => {
|
||||||
const accessToken = event.cookies.get('access_token');
|
const accessToken = event.cookies.get('access_token');
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import { browser } from '$app/environment';
|
import { browser } from '$app/environment';
|
||||||
import { env } from '$env/dynamic/public';
|
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
abstract class APIService {
|
abstract class APIService {
|
||||||
baseURL: string = '/api';
|
|
||||||
api = axios.create({
|
api = axios.create({
|
||||||
withCredentials: true
|
withCredentials: true
|
||||||
});
|
});
|
||||||
@@ -11,11 +9,11 @@ abstract class APIService {
|
|||||||
constructor(accessToken?: string) {
|
constructor(accessToken?: string) {
|
||||||
if (accessToken) {
|
if (accessToken) {
|
||||||
this.api.defaults.headers.common['Authorization'] = `Bearer ${accessToken}`;
|
this.api.defaults.headers.common['Authorization'] = `Bearer ${accessToken}`;
|
||||||
} else {
|
|
||||||
this.api.defaults.baseURL = '/api';
|
|
||||||
}
|
}
|
||||||
if (!browser) {
|
if (browser) {
|
||||||
this.api.defaults.baseURL = (env.PUBLIC_APP_URL ?? 'http://localhost') + '/api';
|
this.api.defaults.baseURL = '/api';
|
||||||
|
} else {
|
||||||
|
this.api.defaults.baseURL = process?.env?.INTERNAL_BACKEND_URL + '/api';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user