diff --git a/backend/src/baserow/config/settings/base.py b/backend/src/baserow/config/settings/base.py index bc2221c5f..256287ac8 100644 --- a/backend/src/baserow/config/settings/base.py +++ b/backend/src/baserow/config/settings/base.py @@ -67,11 +67,11 @@ WSGI_APPLICATION = 'baserow.config.wsgi.application' DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', - 'NAME': 'baserow', - 'USER': 'baserow', - 'PASSWORD': 'baserow', - 'HOST': 'db', - 'PORT': '5432', + 'NAME': os.getenv('DATABASE_NAME', 'baserow'), + 'USER': os.getenv('DATABASE_USER', 'baserow'), + 'PASSWORD': os.getenv('DATABASE_PASSWORD', 'baserow'), + 'HOST': os.getenv('DATABASE_HOST', 'db'), + 'PORT': os.getenv('DATABASE_PORT', '5432'), } } @@ -147,14 +147,14 @@ DATABASE_ROUTERS = ('baserow.contrib.database.database_routers.TablesDatabaseRou MJML_BACKEND_MODE = 'tcpserver' MJML_TCPSERVERS = [ - ('mjml', 28101), + (os.getenv('MJML_SERVER_HOST', 'mjml'), os.getenv('MJML_SERVER_PORT', 28101)), ] -PUBLIC_BACKEND_DOMAIN = 'localhost:8000' -PUBLIC_BACKEND_URL = 'http://localhost:8000' -PUBLIC_WEB_FRONTEND_DOMAIN = 'localhost:3000' -PUBLIC_WEB_FRONTEND_URL = 'http://localhost:3000' +PUBLIC_BACKEND_DOMAIN = os.getenv('PUBLIC_BACKEND_DOMAIN', 'localhost:8000') +PUBLIC_BACKEND_URL = os.getenv('PUBLIC_BACKEND_URL', 'http://localhost:8000') +PUBLIC_WEB_FRONTEND_DOMAIN = os.getenv('PUBLIC_WEB_FRONTEND_DOMAIN', 'localhost:3000') +PUBLIC_WEB_FRONTEND_URL = os.getenv('PUBLIC_WEB_FRONTEND_URL', 'http://localhost:3000') -FROM_EMAIL = 'no-reply@localhost' +FROM_EMAIL = os.getenv('FROM_EMAIL', 'no-reply@localhost') RESET_PASSWORD_TOKEN_MAX_AGE = 60 * 60 * 48 # 48 hours diff --git a/backend/src/baserow/config/settings/demo.py b/backend/src/baserow/config/settings/demo.py index a48cc3f86..60468d4b0 100644 --- a/backend/src/baserow/config/settings/demo.py +++ b/backend/src/baserow/config/settings/demo.py @@ -1,13 +1,4 @@ from .base import * # noqa: F403, F401 -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': 'baserow', - 'USER': 'baserow', - 'PASSWORD': 'baserow', - 'HOST': 'db', - 'PORT': '5432', - } -} +EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' diff --git a/changelog.md b/changelog.md index e3ec7fb39..29c070694 100644 --- a/changelog.md +++ b/changelog.md @@ -16,3 +16,5 @@ * Implemented reset forgotten password functionality. * Fill a newly created table with some initial data. * Enabled the arrow keys to navigate through the fields in the grid view. +* Fixed memory leak bug. +* Use environment variables for all settings. diff --git a/web-frontend/config/nuxt.config.base.js b/web-frontend/config/nuxt.config.base.js index 4cf27a0f8..591d0b9d7 100644 --- a/web-frontend/config/nuxt.config.base.js +++ b/web-frontend/config/nuxt.config.base.js @@ -4,17 +4,5 @@ export default function (base = '@') { base + '/modules/core/module.js', base + '/modules/database/module.js', ], - - env: { - // The API base url, this will be prepended to the urls of the remote calls. - baseUrl: 'http://backend:8000/api/v0', - - // If the API base url must different at the client side it can be changed - // here. - publicBaseUrl: 'http://localhost:8000/api/v0', - - // The public web frontend URL. - publicWebFrontendUrl: 'http://localhost:3000', - }, } } diff --git a/web-frontend/config/nuxt.config.test.js b/web-frontend/config/nuxt.config.test.js index 712449e6c..aa0e51e4f 100644 --- a/web-frontend/config/nuxt.config.test.js +++ b/web-frontend/config/nuxt.config.test.js @@ -9,7 +9,6 @@ export default _.assign({}, base(), { dev: false, debug: false, env: { - // The API base url, this will be prepended to the urls of the remote calls. - baseUrl: 'http://localhost/api/v0', + PRIVATE_BACKEND_URL: 'http://localhost', }, }) diff --git a/web-frontend/modules/core/module.js b/web-frontend/modules/core/module.js index c8f34ca05..c74ce826f 100644 --- a/web-frontend/modules/core/module.js +++ b/web-frontend/modules/core/module.js @@ -19,7 +19,7 @@ export default function DatabaseModule(options) { this.options.mode = 'universal' // Set the default head object, but override the configured head. - // @TODO if a child is a list the new children must be appended instead of overriden. + // @TODO if a child is a list the new children must be appended instead of overridden. this.options.head = _.merge({}, head, this.options.head) // Store must be true in order for the store to be injected into the context. @@ -31,6 +31,25 @@ export default function DatabaseModule(options) { // The core depends on these modules. this.requireModule('@nuxtjs/axios') this.requireModule('cookie-universal-nuxt') + this.requireModule([ + 'nuxt-env', + { + keys: [ + { + key: 'PRIVATE_BACKEND_URL', + default: 'http://backend:8000', + }, + { + key: 'PUBLIC_BACKEND_URL', + default: 'http://localhost:8000', + }, + { + key: 'PUBLIC_WEB_FRONTEND_URL', + default: 'http://localhost:3000', + }, + ], + }, + ]) // Serve the static directory // @TODO we might need to change some things here for production. (See: @@ -50,7 +69,6 @@ export default function DatabaseModule(options) { 'middleware.js', 'plugin.js', 'plugins/auth.js', - 'plugins/clientHandler.js', 'plugins/global.js', 'plugins/vuelidate.js', ] @@ -60,6 +78,12 @@ export default function DatabaseModule(options) { }) }) + // The client handler depends on environment variables so the plugin must be added + // after the nuxt-env module's plugin. + this.appendPlugin({ + src: path.resolve(__dirname, 'plugins/clientHandler.js'), + }) + this.extendRoutes((configRoutes) => { // Remove all the routes created by nuxt. let i = configRoutes.length diff --git a/web-frontend/modules/core/pages/forgotPassword.vue b/web-frontend/modules/core/pages/forgotPassword.vue index d9da1c37c..5357f8a7f 100644 --- a/web-frontend/modules/core/pages/forgotPassword.vue +++ b/web-frontend/modules/core/pages/forgotPassword.vue @@ -90,7 +90,7 @@ export default { this.hideError() try { - const resetUrl = `${process.env.publicWebFrontendUrl}/reset-password` + const resetUrl = `${this.$env.PUBLIC_WEB_FRONTEND_URL}/reset-password` await AuthService(this.$client).sendResetPasswordEmail( this.account.email, resetUrl diff --git a/web-frontend/modules/core/plugins/clientHandler.js b/web-frontend/modules/core/plugins/clientHandler.js index 0eb090c2c..1dda298fb 100644 --- a/web-frontend/modules/core/plugins/clientHandler.js +++ b/web-frontend/modules/core/plugins/clientHandler.js @@ -176,11 +176,11 @@ class ErrorHandler { } } -export default function ({ store }, inject) { +export default function ({ store, app }, inject) { const url = - process.client && process.env.publicBaseUrl - ? process.env.publicBaseUrl - : process.env.baseUrl + (process.client + ? app.$env.PUBLIC_BACKEND_URL + : app.$env.PRIVATE_BACKEND_URL) + '/api/v0' const client = axios.create({ baseURL: url, withCredentials: false, diff --git a/web-frontend/package.json b/web-frontend/package.json index e2278dedb..cf196bffb 100644 --- a/web-frontend/package.json +++ b/web-frontend/package.json @@ -14,9 +14,9 @@ "jest": "jest -i --verbose false test/" }, "dependencies": { - "axios": "0.19.0", "@fortawesome/fontawesome-free": "^5.13.0", "@nuxtjs/axios": "5.8.0", + "axios": "0.19.0", "cookie-universal-nuxt": "2.1.3", "cross-env": "7.0.2", "jwt-decode": "2.2.0", @@ -24,6 +24,7 @@ "node-sass": "4.13.1", "normalize-scss": "7.0.1", "nuxt": "2.12.1", + "nuxt-env": "^0.1.0", "sass-loader": "8.0.2", "vuelidate": "0.7.5" }, diff --git a/web-frontend/yarn.lock b/web-frontend/yarn.lock index efdcf580f..368eea9ff 100644 --- a/web-frontend/yarn.lock +++ b/web-frontend/yarn.lock @@ -7716,6 +7716,11 @@ number-is-nan@^1.0.0: resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d" integrity sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0= +nuxt-env@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/nuxt-env/-/nuxt-env-0.1.0.tgz#8ac50b9ff45391ad3044ea932cbd05f06a585f87" + integrity sha512-7mTao3qG0zfN0hahk3O6SuDy0KEwYmNojammWQsMwhqMn3aUjX4nMYnWDa0pua+2/rwAY9oG53jQtLgJdG7f9w== + nuxt@2.12.1: version "2.12.1" resolved "https://registry.yarnpkg.com/nuxt/-/nuxt-2.12.1.tgz#68489eeeaa287e8b8896d425265c6d951dae8247"