frankcollins3 / PHPokedex

react concepts
0 stars 0 forks source link

process.env object not retrieving endpoints from .env [2:14pm] #6

Closed frankcollins3 closed 1 year ago

frankcollins3 commented 1 year ago

.env: Screen Shot 2023-03-13 at 2 12 36 PM

dependencies: Screen Shot 2023-03-13 at 3 06 58 PM

browser/devtools from console.log() Screen Shot 2023-03-13 at 2 14 50 PM

Screen Shot 2023-03-13 at 2 15 13 PM

frankcollins3 commented 1 year ago

https://stackoverflow.com/questions/66137368/next-js-environment-variables-are-undefined-next-js-10-0-5

forgot about restarting the server that'll probably do it [3:00am]

frankcollins3 commented 1 year ago

iterm:

touch env.local

client: 👎 process.env.local

[3:17pm]

will look into next&&env config later on.

frankcollins3 commented 1 year ago

I wonder if getServerSideProps works but I hear there's a new preferred way to do data handling prebuild in next.js [3:19pm]

frankcollins3 commented 1 year ago

Screen Shot 2023-03-13 at 3 35 20 PM

Screen Shot 2023-03-13 at 3 35 27 PM

next docs: https://nextjs.org/docs/api-reference/next.config.js/environment-variables

Screen Shot 2023-03-13 at 3 37 36 PM

Screen Shot 2023-03-13 at 3 37 16 PM

I'm still kind of confused why you don't see those endpoints anywhere on process.env tv dinner && dvd dinner

do pop up from the next.config

frankcollins3 commented 1 year ago

I also initially put a new module.exports { } beneath the next config export and reset it to be keys within the export obj [3:38pm]

frankcollins3 commented 1 year ago

Screen Shot 2023-03-13 at 3 43 59 PM

[3:44pm]

frankcollins3 commented 1 year ago

nvm forgot to restart the server again this is working. [3:46pm]

frankcollins3 commented 1 year ago

problem. the utility func doesn't have access to process.env Screen Shot 2023-03-13 at 3 47 23 PM

frankcollins3 commented 1 year ago

updated utility function to take parameter

import Axios from 'axios'
const pokeapiURL = `https://pokeapi.co/api/v2/pokemon?limit=300`
// const envURL = process.env.ALLpokemonURL

export default async function APIpokemonALL (url:any|null) {
    let predata = await Axios.get(url || pokeapiURL)
    console.log('predata')
    console.log(predata)    
    return {predata: predata, data: predata.data.results}
}

[3:51pm]

frankcollins3 commented 1 year ago

success. process.env retrieved and passes as a valid string when exported from: next.config.js to be available to every: ----------------> pages/

[3:59pm]