Skip to content

Wondering if env vars are still not supported for baseUrl in RTK Codegen #4463

Closed as not planned

Description

I saw a thread somewhere (lost it, sorry) with grumpy tofu maybe mentioning that somehow codegen doesn't ingest env vars for codegen yet. Yearning to hear that i'm wrong, but somehow when i run the
npx @rtk-query/codegen-openapi openapi-config.ts env var doesn't work.

Thanks in advance

// Or from '@reduxjs/toolkit/query' if not using the auto-generated hooks
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'

const { parsed: { DJANGO_URL }, } = require("dotenv").config({ path: "./../../../.env.local" });
// initialize an empty api service that we'll inject endpoints into later as needed

export const empty_api = createApi({
  // baseQuery: fetchBaseQuery({ baseUrl: 'http://localhost:8000', } ),  //  # <-- Works
  baseQuery: fetchBaseQuery({ baseUrl: DJANGO_URL } ),                   //    <-- Empty base url after codegen
  endpoints: () => ({}),
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions