mirror of
https://github.com/wassname/talk.git
synced 2026-08-01 13:00:55 +08:00
fix: modified uri parsing for mongodb (#2282)
This commit is contained in:
@@ -1,19 +1,21 @@
|
||||
import convict from "convict";
|
||||
import Joi from "joi";
|
||||
import { parseConnectionString } from "mongodb-core";
|
||||
import os from "os";
|
||||
|
||||
import { LOCALES } from "talk-common/helpers/i18n/locales";
|
||||
|
||||
import { InternalError } from "./errors";
|
||||
|
||||
// Add custom format for the mongo uri scheme.
|
||||
convict.addFormat({
|
||||
name: "mongo-uri",
|
||||
validate: (url: string) => {
|
||||
Joi.assert(
|
||||
url,
|
||||
Joi.string().uri({
|
||||
scheme: ["mongodb"],
|
||||
})
|
||||
);
|
||||
parseConnectionString(url, err => {
|
||||
if (err) {
|
||||
throw new InternalError(err, "invalid mongo-uri");
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
declare module "mongodb-core" {
|
||||
export interface ParsedConnectionString {
|
||||
hosts: string[];
|
||||
auth: {};
|
||||
options: {};
|
||||
}
|
||||
|
||||
export interface ParseConnectionStringOptions {
|
||||
/**
|
||||
* Whether the parser should translate options back into camelCase after normalization.
|
||||
*/
|
||||
caseTranslate?: boolean;
|
||||
}
|
||||
|
||||
/** https://github.com/mongodb-js/mongodb-core/blob/master/lib/uri_parser.js */
|
||||
export function parseConnectionString(
|
||||
uri: string,
|
||||
options?: ParseConnectionStringOptions,
|
||||
callback?: (error: Error, result: ParsedConnectionString) => void
|
||||
): void;
|
||||
export function parseConnectionString(
|
||||
uri: string,
|
||||
callback?: (error: Error, result: ParsedConnectionString) => void
|
||||
): void;
|
||||
}
|
||||
Reference in New Issue
Block a user