question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting base path dynamically for production builds.

See original GitHub issue

You usually develop against your server running at some local address, and use some other base path in production, e.g: http://locahost:8080 locally and https://myprodserver in production.

I would like the possibility to change the base path dynamically for creating my production builds.

If I understand correctly this comes directly from the OpenApi-spec-file, as of now, but I would like this to be independent of the OpenApi-spec, maybe as an input param to the cli-tool, or as an override through an environment-variable.

If there already is a way of doing this, without the need to change my OpenApi-spec generated at the backend, I would love to know.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ferdikoomencommented, Jan 25, 2022

@knobel-dk I have use something like this in the past:

setupOpenAPI.ts (imported as one of the first files)

import { OpenAPI } from './myGeneratedClient';

if (process.env.DEBUG) {
   OpenAPI.BASE = 'http://localhost:8080/';
}

Then during a production build the ‘regular’ base is used that was there in the OpenAPI spec.

This works with the Webpack environment plugin: https://webpack.js.org/plugins/environment-plugin/ you need to setup this for your repo. Similar plugins exists for Rollup and others.

1reaction
ferdikoomencommented, Feb 4, 2021

Hi @staklau you can always change the base path bt setting this in OpenAPI.BASE = ‘http://mydomain.com/api’. You can do that based on the environment config or inject it via webpack, whatever works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 2+ - Set base href dynamically - Stack Overflow
If you are using Angular CLI 6, you can use the deployUrl/baseHref options in angular.json (projects > xxx > architect > build >...
Read more >
Angular: Set Base URL Dynamically - Project Codify
If we want to change the base URL, we have two problems to solve: 1. Handle Angular routing to accommodate base URL. 2....
Read more >
Building for Production - Vite
If you are deploying your project under a nested public path, simply specify the base config option and all asset paths will be...
Read more >
Base Path - next.config.js
Base Path added. To deploy a Next.js application under a sub-path of a domain you can use the basePath config option. ... Note:...
Read more >
Dynamic Multiple Base URL with Annotations | Android
Now we need a flag to manipulate base urls for each retrofit call. We can define an annotation class and set it to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found