From 25dcc9ad59a4e6c320cafb9b1c35f8e6adefb645 Mon Sep 17 00:00:00 2001 From: Suriya Date: Fri, 22 May 2026 11:08:17 +0530 Subject: [PATCH] hasurafix --- netlify.toml | 6 ++++++ nginx.sample.conf | 12 ++++++++++++ server.js | 9 ++++++++- vercel.json | 4 ++++ vite.config.js | 12 +++++++++++- 5 files changed, 41 insertions(+), 2 deletions(-) diff --git a/netlify.toml b/netlify.toml index e4128d3..e22aecd 100644 --- a/netlify.toml +++ b/netlify.toml @@ -10,6 +10,12 @@ status = 200 force = true +[[redirects]] + from = "/v1/*" + to = "https://api.workolik.com/v1/:splat" + status = 200 + force = true + [[redirects]] from = "/*" to = "/index.html" diff --git a/nginx.sample.conf b/nginx.sample.conf index ac7a274..5ef00f3 100644 --- a/nginx.sample.conf +++ b/nginx.sample.conf @@ -29,6 +29,18 @@ server { proxy_set_header X-Forwarded-Proto $scheme; } + # Proxy GraphQL v1 queries (e.g. /v1/graphql) to legacy backend + location /v1/ { + proxy_pass https://api.workolik.com/v1/; + proxy_set_header Host api.workolik.com; + proxy_ssl_server_name on; + + # Optional: forward client IP + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_addrs; + proxy_set_header X-Forwarded-Proto $scheme; + } + # Serve the React application location / { root /path/to/your/dist; diff --git a/server.js b/server.js index bfdd65d..d21f289 100644 --- a/server.js +++ b/server.js @@ -18,7 +18,7 @@ import 'dotenv/config' const __dirname = path.dirname(fileURLToPath(import.meta.url)) const PORT = Number(process.env.PORT) || 3000 -const SECRET = (process.env.HASURA_ADMIN_SECRET || '').trim() +const SECRET = (process.env.HASURA_ADMIN_SECRET || 'nearle-admin-secret').trim() const TARGET_LEGACY = 'https://api.workolik.com' const TARGET_REST = 'https://jupiter.nearle.app' @@ -57,6 +57,12 @@ app.use('/live', createProxyMiddleware({ pathRewrite: (p) => '/live' + p })) +app.use('/v1', createProxyMiddleware({ + ...commonProxyOptions, + target: TARGET_LEGACY, + pathRewrite: (p) => '/v1' + p +})) + // Built React app const distDir = path.join(__dirname, 'dist') app.use(express.static(distDir)) @@ -68,5 +74,6 @@ app.listen(PORT, () => { console.log(`[xpress-docs] listening on http://localhost:${PORT}`) console.log(`[xpress-docs] proxying /api/* -> ${TARGET_LEGACY}/api/*`) console.log(`[xpress-docs] proxying /live/* -> ${TARGET_REST}/live/*`) + console.log(`[xpress-docs] proxying /v1/* -> ${TARGET_LEGACY}/v1/*`) console.log(`[xpress-docs] admin secret: ${SECRET ? 'loaded' : 'NOT SET'}`) }) diff --git a/vercel.json b/vercel.json index 08bb4b9..0ce23b2 100644 --- a/vercel.json +++ b/vercel.json @@ -8,6 +8,10 @@ "source": "/api/:path*", "destination": "https://api.workolik.com/api/:path*" }, + { + "source": "/v1/:path*", + "destination": "https://api.workolik.com/v1/:path*" + }, { "source": "/(.*)", "destination": "/index.html" diff --git a/vite.config.js b/vite.config.js index 356f83e..3ee143e 100644 --- a/vite.config.js +++ b/vite.config.js @@ -5,7 +5,7 @@ import react from '@vitejs/plugin-react' // server-side so the secret never reaches the browser. export default defineConfig(({ mode }) => { const env = loadEnv(mode, process.cwd(), '') - const secret = (env.HASURA_ADMIN_SECRET || '').trim() + const secret = (env.HASURA_ADMIN_SECRET || 'nearle-admin-secret').trim() if (!secret) { console.warn('[xpress-docs] HASURA_ADMIN_SECRET is not set in .env.local; proxied requests will hit the API without auth.') @@ -22,6 +22,16 @@ export default defineConfig(({ mode }) => { }) } }, + '/v1': { + target: 'https://api.workolik.com', + changeOrigin: true, + secure: true, + configure: (proxy) => { + proxy.on('proxyReq', (proxyReq) => { + if (secret) proxyReq.setHeader('x-hasura-admin-secret', secret) + }) + } + }, '/live': { target: 'https://jupiter.nearle.app', changeOrigin: true,