Skip to content
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
2 changes: 0 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ jobs:

- run: npm ci
- run: npm run build
env:
VITE_CORS_PROXY_URL: ${{ vars.VITE_CORS_PROXY_URL }}
- run: cp dist/index.html dist/404.html

- uses: actions/upload-pages-artifact@v3
Expand Down
2 changes: 1 addition & 1 deletion env.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <reference types="vite/client" />

interface ImportMetaEnv {
readonly VITE_CORS_PROXY_URL?: string;
// no custom env vars needed — production uses corsproxy.io
}

declare module '*.vue' {
Expand Down
21 changes: 19 additions & 2 deletions src/http-common.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
import axios from 'axios';

// Public API client — proxied through Vite in dev, Cloudflare Worker in prod.
const TARGET_BASE = 'https://www.reservauto.net';

// Public API client — proxied through Vite in dev, corsproxy.io in prod.
const apiClient = axios.create({
baseURL: import.meta.env.DEV ? '/api' : (import.meta.env.VITE_CORS_PROXY_URL || 'https://communauto-cors-proxy.<your-subdomain>.workers.dev'),
baseURL: import.meta.env.DEV ? '/api' : TARGET_BASE,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
});

if (!import.meta.env.DEV) {
apiClient.interceptors.request.use((config) => {
const targetUrl = new URL(config.url!, TARGET_BASE);
if (config.params) {
for (const [k, v] of Object.entries(config.params as Record<string, unknown>)) {
if (v !== undefined && v !== null) targetUrl.searchParams.set(k, String(v));
}
config.params = undefined;
}
config.baseURL = '';
config.url = `https://corsproxy.io/?url=${encodeURIComponent(targetUrl.toString())}`;
Comment on lines +14 to +24
return config;
});
}

// Authenticated REST API client — direct to restapifrontoffice
const restApi = axios.create({
baseURL: 'https://restapifrontoffice.reservauto.net',
Expand Down
Loading