“So verbergen Sie den API -Schlüssel in React” Code-Antworten

URLs in .Env in React App verbergen

WARNING: Do not store any secrets (such as private API keys) in your React app!

Environment variables are embedded into the build, meaning anyone can view them by inspecting your app's files.

outside our src folder create .env file and add it to gitignore
REACT_APP_WEATHER_API_KEY=123456
inside where you want to access the variable 
const API_KEY = process.env.REACT_APP_WEATHER_API_KEY;

make sure to restart the server
Gorgeous Goldfinch

So verbergen Sie den API -Schlüssel in React

// .env

REACT_APP_API_KEY=your_api_key  <-- yes
API_KEY=your_api_key            <-- no

// Example (from 이준형's response):
REACT_APP_WEATHER_API_KEY=123456
Friendly Flatworm

Ähnliche Antworten wie “So verbergen Sie den API -Schlüssel in React”

Fragen ähnlich wie “So verbergen Sie den API -Schlüssel in React”

Weitere verwandte Antworten zu “So verbergen Sie den API -Schlüssel in React” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen