Skip to content

Vercel API config#61

Open
fernando-syslabs wants to merge 8 commits intosyscoin:mainfrom
fernando-syslabs:vercel-api-config
Open

Vercel API config#61
fernando-syslabs wants to merge 8 commits intosyscoin:mainfrom
fernando-syslabs:vercel-api-config

Conversation

@fernando-syslabs
Copy link
Copy Markdown

No description provided.

DevElCuy and others added 5 commits January 23, 2026 14:33
…loyment

Enables deploying frontend to Vercel while running API on a separate server
by making the API base URL configurable via NEXT_PUBLIC_API_BASE_URL env var.                                                                               Also adds CORS headers support via CORS_ALLOWED_ORIGIN.
  utils/api-base-url.ts:1 centralizes API_BASE_URL, trimming any trailing slash from NEXT_PUBLIC_API_BASE_URL. All callers concatenate their own /api/... paths,
  so this change removes subtle bugs where a configured base like https://example.com/ would yield double
  slashes in requests.
  The admin list, login, and transfer detail pages
  (pages/admin/index.tsx:1-43, pages/admin/login.tsx:8-33, pages/admin/transfer/[id].tsx:26-55)
  now import API_BASE_URL so every admin fetch uses ${API_BASE_URL}/api/... instead of assuming same-origin.
  This unblocks deploying the admin frontend separately from the API server.
  lib/session.ts:15-24 introduces the ADMIN_COOKIE_DOMAIN env toggle so the iron-session cookie can be scoped
  to a shared parent domain when the API and frontend run on different hosts.
  Any admin-side fetch that needs to send/receive the session cookie now opts in with credentials:
  "include" (pages/admin/index.tsx:19-24, pages/admin/login.tsx:18-33, pages/admin/transfer/[id].tsx:39-96),
  ensuring the browser actually forwards the cookie even when calling a cross-origin API_BASE_URL.
  pages/admin/index.tsx:63-133 replaced the previous direct TransferModel query with a server-side fetch
  to the new /api/admin/transfers endpoint, forwarding cookies and redirecting when the session has expired;
  this allows the same page logic to run whether the UI is deployed with or without direct DB access.

  pages/admin/transfer/[id].tsx:35-288 follows the same pattern for the detail view: list/detail fetches
  come from ${API_BASE_URL}/api/admin/transfers/:id, session enforcement is centralized through withSessionSsr,
  and HTTP errors (401/404) now short-circuit to login/ not-found pages.

  New API route files pages/api/admin/transfers/index.ts:1-43 and pages/api/admin/transfers/[id].ts:1-31 expose
  paginated listing and detail lookups that were previously embedded in getServerSideProps, encapsulating
  DB access behind adminSessionGuard.
@jonathanlmatos
Copy link
Copy Markdown

The admin UI now fetches transfer data through the new /api/admin/transfers endpoints (list and detail) instead of touching MongoDB directly, so SSR logic simply forwards cookies, handles 401/404 responses, and can run even when the frontend is deployed separately from the API/database.
Those new API routes wrap pagination, filtering, and record lookup behind adminSessionGuard, keeping DB access server-side. To support split deployments, every frontend fetch now prepends a configurable NEXT_PUBLIC_API_BASE_URL, trailing slashes are stripped via utils/api-base-url.ts, and next.config.js applies CORS headers using the CORS_ALLOWED_ORIGIN env var.
Admin pages include that helper, send credentials with login/logout/detail/update requests, and lib/session.ts optionally scopes the admin cookie with ADMIN_COOKIE_DOMAIN so sessions survive across hosts. Finally, .env.local was sanitized with dummy values and the README’s env table documents the new knobs so teams know how to configure cross-origin setups.

jagdeep sidhu and others added 3 commits March 3, 2026 10:27
…t frontend/backend deploys

Handle CORS and preflight at API guard/route level so OPTIONS is processed before auth, and remove invalid global wildcard+credentials headers. Complete API_BASE_URL adoption across remaining frontend calls and tighten method handling/docs to prevent admin login/session breakage in separated frontend/backend setups.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants