Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not return value on Interpolation of variables #182

Open
2 tasks done
lazuee opened this issue Jul 12, 2024 · 2 comments
Open
2 tasks done

Does not return value on Interpolation of variables #182

lazuee opened this issue Jul 12, 2024 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@lazuee
Copy link

lazuee commented Jul 12, 2024

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.10.0

Plugin version

No response

Node.js version

20.12.2

Operating system

Windows

Operating system version (i.e. 20.04, 11.3, 10)

23H2

Description

import envSchema, { JSONSchemaType } from 'env-schema';

export interface Env {
  DATABASE_USER: string;
  DATABASE_PASSWORD: string;
  DATABASE_HOST: string;
  DATABASE_PORT: number;
  DATABASE_NAME: string;
  DATABASE_URL: string;
}

const schema: JSONSchemaType<Env> = {
  type: 'object',
  required: ['DATABASE_USER', 'DATABASE_PASSWORD', 'DATABASE_HOST', 'DATABASE_PORT', 'DATABASE_NAME', 'DATABASE_URL'
  ],
  properties: {
    DATABASE_USER: {
      type: 'string',
    },
    DATABASE_PASSWORD: {
      type: 'string',
    },
    DATABASE_HOST: {
      type: 'string',
    },
    DATABASE_PORT: {
      type: 'number',
    },
    DATABASE_NAME: {
      type: 'string',
    },
    DATABASE_URL: {
      type: 'string',
    },
  },
};

const env = envSchema({
  dotenv: true,
  schema,
});

console.log(env.DATABASE_URL); // result: mysql://${DATABASE_USER}:${DATABASE_PASSWORD}@${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}?ssl-mode=REQUIRED
console.log(process.env.DATABASE_URL); // expected result: mysql://root:pass@localhost:3306/db_name?ssl-mode=REQUIRED
DATABASE_USER="root"
DATABASE_PASSWORD="pass"
DATABASE_HOST="localhost"
DATABASE_PORT="3306"
DATABASE_NAME="db_name"
DATABASE_URL="mysql://${DATABASE_USER}:${DATABASE_PASSWORD}@${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}?ssl-mode=REQUIRED"

Link to code that reproduces the bug

No response

Expected Behavior

No response

@Eomm
Copy link
Member

Eomm commented Jul 13, 2024

We don't use any additional plugins, you need to add the https://www.npmjs.com/package/dotenv-expand one.

We may implement a plugins option in this plugin as we did for ajv https://fastify.dev/docs/latest/Reference/Validation-and-Serialization/#ajv-plugins
but I would not add this dep to our dependancies.

@Eomm Eomm added enhancement New feature or request good first issue Good for newcomers labels Jul 13, 2024
@lazuee
Copy link
Author

lazuee commented Jul 13, 2024

Thank you for the suggestion. I added the dotenv-expand package, and it's now working properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants