score:2
you can set in .env file another variable for your endpoint, for example:
react_app_api_endpoint=http://localhost:8000/api
public_url
is already used as base url to react get the dependencies of your application.
in your component you can get the environment variable this way:
const { react_app_api_endpoint } = process.env;
const response = await fetch(`${react_app_api_endpoint}/login`, {
method: "post",
headers: { "content-type": "application/json" },
credentials: "include",
body: json.stringify({
username,
password,
}),
});
score:1
public_url reference documentation
https://create-react-app.dev/docs/using-the-public-folder/
it must be used for external web resource like icon, image, css. it is meant for internal reference to current web page link.
score:2
Source: stackoverflow.com
Related Query
- Setting PUBLIC-URL in .env file React application
- React Public URL env variable
- How to read the current URL in the react application
- How to import file from public folder in react application?
- Selenium-ide, File upload not working for react application
- React sitemap.xml file in public directory is not showing after build
- IIS URL redirect on sub application holding react SPA
- Changing Axios baseUrl accessible from env file after building React App
- Can´t access my public folder from css file in React App
- React not fetching data from the updated env file
- Nodejs - React download file from s3 bucket using pre-signed url
- How to read xml from file inside public directory in react project in React JS?
- How to override env variables in React JS application with Kuberenetes?
- How to make react router, change what file is rendering based on the url
- Setting window.location.href in react SPA production application yields unexpected results
- How to save uploaded file url in firebase using react
- Getting API URL from the External File which is not a part of the React app
- React Builder tool won't set public url correctly
- File Preview in React FilePond not showing up when setting initial file
- Link to an outside URL in my React application
- react router public path url
- How to apply CSS style to HTML file that is inside the public folder of React JS
- Image file cannot be found when using URL loader of webpack with React & Django
- Error setting up new React project when moving index.html to public folder
- react dynamically build href file URL using map() method
- Import or require a bundled js file created by react application
- How to get the URL in webpack - react application
- React app not loading js file when accessing it with a non home page url
- run another application when there is a URL with a question mark and is equal to react nginx
- Node js url is working only on private window in React application
More Query from same tag
- How to place the last div within a div at the end of the div containing it using css?
- React Axios useEffect hook, different types of errors when rendering to the user interface
- How to Route to different components in ReactJS
- Reactjs function invoking on page load before onClick event
- React: Why isn't my context value updated?
- Re-use navbar component with multiple components
- React.js: Uncaught RangeError: Maximum call stack size exceeded
- How do I set background color of color picker from API call?
- "'Undefined is not an object (evaluating 'row[0].val')" error in react native
- How to stream webcam into mobile browser by using ReactJs?
- How to disable onClick function on a single table row?
- Counter in the app doesn't function as intended
- Why can't I type in input text field?
- Components doesn't re-render on Login
- ReactJS onClick get DIV IDs
- concatenation jsx with Link doesn't work
- How to open Drawer from another component
- React, React Router and Flux: “dispatch in the middle of a dispatch” when I try to clear the messages on store
- display primary and secondary menu using BrowserRouter React Component
- ReactJS/Axios: Unhandled Rejection (Error): Request failed with status code 500
- Change value on dynamic input fields in reactjs
- React.js -- Bootstrap / Reactstrap -- z-index does not work on Carousel
- How to auto-refresh time in React when using 'date-fns' library
- esModuleInterop flag set, still getting default import error
- Heroku - Seperate frontend and backend with Nginx on same domain
- Api request still multiple times in set interval
- React rendering conditionally
- How can I handle return type for fetch async function?
- Transform JSX only
- Using plugin-transform-react-jsx in Create React App