skohub-io / skohub-vocabs

A lightweight tool to publish SKOS Vocabularies
https://skohub.io/
Apache License 2.0
34 stars 25 forks source link

Environment Variables in Gatsby #130

Closed sroertgen closed 1 year ago

sroertgen commented 3 years ago

Working on #119 I had some issues using the environment variables.

When I copy the .env.example to .env.production and add BASEURL=/public, e.g.

PORT=3000
SECRET=YOUR_GITHUB_WEBHOOK_SECRET
INBOX=https://test.skohub.io/inbox?target={id}
FOLLOWERS=https://test.skohub.io/followers?subject={id}
ACTOR=https://test.skohub.io/{+path}
PUBLIC_KEY="-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyr05JFWnpFGTr423+IRU\nHOgAuoF0RSxdwPpvXbX5uh+2jUBvhXzzklhc5nwfE3XruHTifJWyXFWucJlDPEI1\nxR5p0C0zfqY74ioEoKorifc8no8ZDTQRvIIEqNe0Ezbe085Foc3UWG1kimPcPlqU\nnsgCYgO4UWJ27qABE+yGDykZALdMlAt+dwOPD10NcqmvupH5pgWZJJ9vW2ErTaDt\n2R52JIpqH6CvCsI7jpLyYH60W0N0J0sjSH95lZnyVDYDbplIEPUPpGKYSVJW+dNU\nCxReZBiwS76VDQhyl1lT5JusRCogvsX/bwJrIZ8fJcOBArDx2skknzUHKkjNITsD\nTwIDAQAB\n-----END PUBLIC KEY-----\n"
BUILD_URL=https://test.skohub.io/build
BASEURL=/public

and then run npm run build, the BASEURL is only picked up in index.js, all other links are build without /public.

Reading here: https://www.gatsbyjs.com/docs/how-to/local-development/environment-variables/ I think it's because the following is missing in gatsby-config.js and gatsby-node.js:

require("dotenv").config({
  path: `.env.${process.env.NODE_ENV}`,
})

Adding this part in both files, every link gets build as expected BUT the links in index.js. The links build in this file now have double BASEURL, e.g. /public/public/....

I think this is because of using Gatsby link component there: https://github.com/skohub-io/skohub-vocabs/blob/8f57d586fb394f8eb82afceca69b48f9a39dcf21/src/components/index.js#L15-L17

Because the pathPrefix variable gets now picked up in gatsby-config.js and is automatically added in Gatsby Link components, it gets double added there.

Just wanted to check back, if I'm missing something out here or if this is somehow wanted behaviour.

sroertgen commented 1 year ago

closed with #184