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

feat(sequelize): handle query string host value #12041

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/sequelize.js
Expand Up @@ -211,6 +211,13 @@ class Sequelize {
}

if (urlParts.query) {
// Allow host query argument to override the url host.
// Enables specifying domain socket hosts which cannot be specified via the typical
// host part of a url.
if (urlParts.query.host) {
options.host = urlParts.query.host;
}

if (options.dialectOptions)
Object.assign(options.dialectOptions, urlParts.query);
else
Expand Down
7 changes: 7 additions & 0 deletions test/unit/configuration.test.js
Expand Up @@ -179,5 +179,12 @@ describe('Sequelize', () => {
expect(dialectOptions.application_name).to.equal('client');
expect(dialectOptions.ssl).to.equal('true');
});

it('should use query string host if specified', () => {
const sequelize = new Sequelize('mysql://localhost:9821/dbname?host=example.com');

const options = sequelize.options;
expect(options.host).to.equal('example.com');
});
});
});