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

Allow autoConfig with callback #381

Merged
merged 5 commits into from
Jun 12, 2024

Conversation

jean-michelet
Copy link
Contributor

Can be usefull to autoload plugins:

import fastifyMysql from "@fastify/mysql";

export const autoConfig = (fastify) => {
  return {
    promise: true,
    host: fastify.config.MYSQL_HOST,
    user: fastify.config.MYSQL_USER,
    password: fastify.config.MYSQL_PASSWORD,
    database: fastify.config.MYSQL_DATABASE,
    port: Number(fastify.config.MYSQL_PORT)
  }
}

export default fastifyMysql

README.md Show resolved Hide resolved
index.js Outdated
Comment on lines 285 to 295
let pluginOptions
if (typeof pluginConfig === 'function') {
pluginOptions = function (fastify) {
return { ...pluginConfig(fastify), ...overrideConfig }
}

pluginOptions.prefix = pluginConfig.prefix
} else {
pluginOptions = { ...pluginConfig, ...overrideConfig }
}

Copy link
Contributor Author

@jean-michelet jean-michelet Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might do the job, but I think the whole component would benefit greatly from a major refactoring.
Right now, it really looks spaghetti code imho, it's hard to introduce changes cleanly.

EDIT: maybe with:

pluginOptions.prefix = overrideConfig.prefix ?? pluginConfig.prefix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open to work on it btw, but after the demo.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That'd be fantastic, thx 'b

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #383

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina
Copy link
Member

@climba03003 ptal

Copy link
Member

@climba03003 climba03003 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mcollina mcollina merged commit a802a8f into fastify:master Jun 12, 2024
17 checks passed
@jean-michelet jean-michelet mentioned this pull request Jun 17, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants