diff --git a/packages/server/src/integrations/couchdb.ts b/packages/server/src/integrations/couchdb.ts index 079f646b60..c271fb12b2 100644 --- a/packages/server/src/integrations/couchdb.ts +++ b/packages/server/src/integrations/couchdb.ts @@ -9,6 +9,7 @@ import { QueryType, } from "@budibase/types" import { db as dbCore } from "@budibase/backend-core" +import { HOST_ADDRESS } from "./utils" interface CouchDBConfig { url: string @@ -28,7 +29,7 @@ const SCHEMA: Integration = { url: { type: DatasourceFieldType.STRING, required: true, - default: "http://localhost:5984", + default: `http://${HOST_ADDRESS}:5984`, }, database: { type: DatasourceFieldType.STRING, diff --git a/packages/server/src/integrations/elasticsearch.ts b/packages/server/src/integrations/elasticsearch.ts index 7ae0295298..af03baaef1 100644 --- a/packages/server/src/integrations/elasticsearch.ts +++ b/packages/server/src/integrations/elasticsearch.ts @@ -8,6 +8,7 @@ import { } from "@budibase/types" import { Client, ClientOptions } from "@elastic/elasticsearch" +import { HOST_ADDRESS } from "./utils" interface ElasticsearchConfig { url: string @@ -29,7 +30,7 @@ const SCHEMA: Integration = { url: { type: DatasourceFieldType.STRING, required: true, - default: "http://localhost:9200", + default: `http://${HOST_ADDRESS}:9200`, }, ssl: { type: DatasourceFieldType.BOOLEAN, diff --git a/packages/server/src/integrations/microsoftSqlServer.ts b/packages/server/src/integrations/microsoftSqlServer.ts index 831fcd3d20..8e8e84f533 100644 --- a/packages/server/src/integrations/microsoftSqlServer.ts +++ b/packages/server/src/integrations/microsoftSqlServer.ts @@ -22,6 +22,7 @@ import { finaliseExternalTables, SqlClient, checkExternalTables, + HOST_ADDRESS, } from "./utils" import Sql from "./base/sql" import { MSSQLTablesResponse, MSSQLColumn } from "./base/types" @@ -88,7 +89,6 @@ const SCHEMA: Integration = { user: { type: DatasourceFieldType.STRING, required: true, - default: "localhost", }, password: { type: DatasourceFieldType.PASSWORD, @@ -96,7 +96,7 @@ const SCHEMA: Integration = { }, server: { type: DatasourceFieldType.STRING, - default: "localhost", + default: HOST_ADDRESS, }, port: { type: DatasourceFieldType.NUMBER, diff --git a/packages/server/src/integrations/mongodb.ts b/packages/server/src/integrations/mongodb.ts index c9852e4c7a..dea752502d 100644 --- a/packages/server/src/integrations/mongodb.ts +++ b/packages/server/src/integrations/mongodb.ts @@ -22,6 +22,7 @@ import { InsertManyResult, } from "mongodb" import environment from "../environment" +import { HOST_ADDRESS } from "./utils" export interface MongoDBConfig { connectionString: string @@ -51,7 +52,7 @@ const getSchema = () => { connectionString: { type: DatasourceFieldType.STRING, required: true, - default: "mongodb://localhost:27017", + default: `mongodb://${HOST_ADDRESS}:27017`, display: "Connection string", }, db: { diff --git a/packages/server/src/integrations/mysql.ts b/packages/server/src/integrations/mysql.ts index db3819f468..fd9d57d255 100644 --- a/packages/server/src/integrations/mysql.ts +++ b/packages/server/src/integrations/mysql.ts @@ -21,6 +21,7 @@ import { generateColumnDefinition, finaliseExternalTables, checkExternalTables, + HOST_ADDRESS, } from "./utils" import dayjs from "dayjs" import { NUMBER_REGEX } from "../utilities" @@ -49,7 +50,7 @@ const SCHEMA: Integration = { datasource: { host: { type: DatasourceFieldType.STRING, - default: "localhost", + default: HOST_ADDRESS, required: true, }, port: { diff --git a/packages/server/src/integrations/oracle.ts b/packages/server/src/integrations/oracle.ts index 83803906be..9104aadbcc 100644 --- a/packages/server/src/integrations/oracle.ts +++ b/packages/server/src/integrations/oracle.ts @@ -22,6 +22,7 @@ import { finaliseExternalTables, getSqlQuery, SqlClient, + HOST_ADDRESS, } from "./utils" import Sql from "./base/sql" import { @@ -63,7 +64,7 @@ const SCHEMA: Integration = { datasource: { host: { type: DatasourceFieldType.STRING, - default: "localhost", + default: HOST_ADDRESS, required: true, }, port: { diff --git a/packages/server/src/integrations/postgres.ts b/packages/server/src/integrations/postgres.ts index 635d834761..05a519da64 100644 --- a/packages/server/src/integrations/postgres.ts +++ b/packages/server/src/integrations/postgres.ts @@ -21,6 +21,7 @@ import { finaliseExternalTables, SqlClient, checkExternalTables, + HOST_ADDRESS, } from "./utils" import Sql from "./base/sql" import { PostgresColumn } from "./base/types" @@ -72,7 +73,7 @@ const SCHEMA: Integration = { datasource: { host: { type: DatasourceFieldType.STRING, - default: "localhost", + default: HOST_ADDRESS, required: true, }, port: { diff --git a/packages/server/src/integrations/redis.ts b/packages/server/src/integrations/redis.ts index 6a6331ccd4..e127cddd56 100644 --- a/packages/server/src/integrations/redis.ts +++ b/packages/server/src/integrations/redis.ts @@ -6,6 +6,7 @@ import { QueryType, } from "@budibase/types" import Redis from "ioredis" +import { HOST_ADDRESS } from "./utils" interface RedisConfig { host: string @@ -28,7 +29,7 @@ const SCHEMA: Integration = { host: { type: DatasourceFieldType.STRING, required: true, - default: "localhost", + default: HOST_ADDRESS, }, port: { type: DatasourceFieldType.NUMBER, diff --git a/packages/server/src/integrations/utils.ts b/packages/server/src/integrations/utils.ts index f73f522357..1ba379da9e 100644 --- a/packages/server/src/integrations/utils.ts +++ b/packages/server/src/integrations/utils.ts @@ -13,6 +13,7 @@ import { DEFAULT_BB_DATASOURCE_ID, } from "../constants" import { helpers } from "@budibase/shared-core" +import env from "../environment" const DOUBLE_SEPARATOR = `${SEPARATOR}${SEPARATOR}` const ROW_ID_REGEX = /^\[.*]$/g @@ -92,6 +93,14 @@ export enum SqlClient { ORACLE = "oracledb", } +const isCloud = env.isProd() && !env.SELF_HOSTED +const isSelfHost = env.isProd() && env.SELF_HOSTED +export const HOST_ADDRESS = isSelfHost + ? "host.docker.internal" + : isCloud + ? "" + : "localhost" + export function isExternalTableID(tableId: string) { return tableId.includes(DocumentType.DATASOURCE) }