Move obsidian reference to a proxy at /metadata and make it env configurable with OBSIDIAN_BEACHHEAD_SERVER.

This commit is contained in:
Joshua Coles 2023-09-29 10:23:55 +01:00
parent cfec7982e0
commit cf6e26b890
3 changed files with 18 additions and 6 deletions

1
.gitignore vendored
View File

@ -22,3 +22,4 @@ dist-ssr
*.njsproj
*.sln
*.sw?
/.env

View File

@ -61,7 +61,7 @@ export function LargeSelect() {
queryKey: ['obsidian-metadata'],
initialData: [],
queryFn: async () => {
const response = await fetch("http://100.115.154.44:9002/metadata")
const response = await fetch("/metadata")
const fullData: any[] = await response.json();
return R.sortBy(v => -(v.data.backlinks?.length ?? 0), fullData.map(md => ({

View File

@ -1,10 +1,21 @@
import {defineConfig} from 'vite'
import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react-swc'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
server: {
host: '0.0.0.0'
export default defineConfig(({ command, mode }) => {
// Load env file based on `mode` in the current working directory.
// Set the third parameter to '' to load all env regardless of the `VITE_` prefix.
const env = loadEnv(mode, process.cwd(), '')
return {
plugins: [react()],
server: {
host: '0.0.0.0',
proxy: {
'/metadata': {
target: env['OBSIDIAN_BEACHHEAD_SERVER']
}
}
}
}
})