J'utilise NextJs pour créer une application. J'ai deux URL différentes pour la production et le développement et je veux accéder à l'URL correspondante à l'environnement pour le client. J'ai suivi ce guide mais mon PROCESS.ENV.API_URL sur le développement est vide.URL de production pour nextjs
Voici mes fichiers:
.env:
API_URL=https://my-staging-url.com
.env.production:
API_URL=https://my-production-url.com
.babelrc:
{
"presets": [
"next/babel"
],
"env": {
"development": {
"plugins": ["inline-dotenv"]
},
"production": {
"plugins": ["transform-inline-environment-variables"]
}
}
}
l'environnement d'utilisation variable:
import 'isomorphic-fetch';
export const SET_QUERY = 'SET_QUERY';
export const CLEAR_SEARCH = 'CLEAR_SEARCH';
export const START_FETCHING_SEARCH = 'START_FETCHING_SEARCH';
export const SET_SEARCH_RESULTS = 'SET_SEARCH_RESULTS';
export const FETCHING_SEARCH_FAILED = 'FETCHING_SEARCH_FAILED';
export const getSearch = value => {
const url = `${process.env.API_URL}search?q=${value}`; // THIS IS EMPTY
console.log(url);
return fetch(url);
};
// Implement search action
export const doSearch = query => dispatch => {
dispatch({ type: START_FETCHING_SEARCH });
return dispatch => {
return getSearch(query).then(response => {
dispatch({ type: SET_SEARCH_RESULTS });
},() => {
dispatch({ type: FETCHING_SEARCH_FAILED });
});
};
};
export const clearSearch =() => dispatch => {
return dispatch({ type: CLEAR_SEARCH })
};
Espoir qui aide, Cheers!