Skip to content
This repository was archived by the owner on May 13, 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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ If you're looking to develop or test Parseable Console, you can follow the steps
4. Run `pnpm dev` to start the console.
5. Open `http://localhost:3001` in your browser.

Enabling hot reload:

1. Disable CORS on the server by setting `P_CORS=false`.
2. Configure the following environment variables:
```
VITE_USE_BASIC_AUTH=true
VITE_USERNAME=username
VITE_PASSWORD=password
```

To test production build

1. Run `pnpm build:test` to create a release build in test mode.
Expand Down
27 changes: 26 additions & 1 deletion src/api/axios.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
import { signOutHandler } from '@/utils';
import axios from 'axios';
import _ from 'lodash';
import Cookies from 'js-cookie';

const baseURL = import.meta.env.VITE_PARSEABLE_URL ?? '/';
const useBasicAuth = import.meta.env.VITE_USE_BASIC_AUTH;

const instance = axios.create({ baseURL, withCredentials: true });
const createAxiosInstance = () => {
const defaultOpts = { baseURL, withCredentials: true };
const opts = (() => {
if (_.isString(useBasicAuth) && useBasicAuth === 'true') {
const username = import.meta.env.VITE_USERNAME;
const password = import.meta.env.VITE_PASSWORD;
if (!_.isString(username) || !_.isString(password)) return defaultOpts;

// server will always send cookies
// creating mock cookies to avoid updating existing code since this implementation is focused on development only
Cookies.set('username', username);
Cookies.set('session', 'mock-key');
const credentials = btoa(`${username}:${password}`);
const authHeader = `Basic ${credentials}`;
return { baseURL, withCredentials: false, headers: { Authorization: authHeader } };
} else {
return defaultOpts;
}
})();
return axios.create(opts);
};

const instance = createAxiosInstance();

instance.interceptors.request.use(
(request) => {
Expand Down
3 changes: 3 additions & 0 deletions src/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

interface ImportMetaEnv {
readonly VITE_PARSEABLE_URL?: string;
readonly VITE_USE_BASIC_AUTH?: string;
readonly VITE_USERNAME?: string;
readonly VITE_PASSWORD?: string;
}

interface ImportMeta {
Expand Down