Gillette
Gillette
Explore posts from servers
NNuxt
Created by Gillette on 6/18/2024 in #❓・help
Nuxt ENV not working in docker container
Apparently, by default, Nuxt only reads system envs that start with "NUXT_", example: "NUXT_DBHOST". So there are 2 solutions: - Change the env names in the docker compose, and add the NUXT prefix to all of them. - Configure nuxt to remove/change the prefix (https://github.com/unjs/nitro/issues/1836#issuecomment-1770116095). This can be done by adding the following to nuxt config:
runtimeConfig: {
nitro: {
// Remove mandatory NUXT_ from system runtime variables
envPrefix: '',
},
}
runtimeConfig: {
nitro: {
// Remove mandatory NUXT_ from system runtime variables
envPrefix: '',
},
}
5 replies
NNuxt
Created by Gillette on 6/18/2024 in #❓・help
Nuxt ENV not working in docker container
Envs in nuxt are read at build time and injected into the compiled solution. Thanks to the runtime config, it also has the capability of reading runtime system envs
5 replies
NNuxt
Created by Gillette on 6/18/2024 in #❓・help
Nuxt ENV not working in docker container
I have solved the issue, documentation is not good at explaining this...
5 replies
NNuxt
Created by Gillette on 6/18/2024 in #❓・help
Nuxt ENV not working in docker container
Nuxt runtime config:
runtimeConfig: {
JWT_SECRET: process.env.JWT_SECRET as string,
JWT_EXPIRATION: process.env.JWT_EXPIRATION || '900',
PASSWORD_SALT_ROUNDS: process.env.PASSWORD_SALT_ROUNDS || '10',

DB_NAME: process.env.DB_NAME,
DB_HOST: process.env.DB_HOST,
DB_USER: process.env.DB_USER,
DB_PASSWORD: process.env.DB_PASSWORD,
DB_PORT: process.env.DB_PORT || '5432',

MAX_TRANSACTION_FILE_SIZE: Number(
process.env.MAX_TRANSACTION_FILE_SIZE || 1024 * 1024 * 10
) //10 MB
},
runtimeConfig: {
JWT_SECRET: process.env.JWT_SECRET as string,
JWT_EXPIRATION: process.env.JWT_EXPIRATION || '900',
PASSWORD_SALT_ROUNDS: process.env.PASSWORD_SALT_ROUNDS || '10',

DB_NAME: process.env.DB_NAME,
DB_HOST: process.env.DB_HOST,
DB_USER: process.env.DB_USER,
DB_PASSWORD: process.env.DB_PASSWORD,
DB_PORT: process.env.DB_PORT || '5432',

MAX_TRANSACTION_FILE_SIZE: Number(
process.env.MAX_TRANSACTION_FILE_SIZE || 1024 * 1024 * 10
) //10 MB
},
Use of ENV in the code:
const { DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_PORT } = useRuntimeConfig()
console.log(DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_PORT)
const { DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_PORT } = useRuntimeConfig()
console.log(DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_PORT)
5 replies