1
0
Fork 0
mirror of https://gitlab.com/bramw/baserow.git synced 2025-04-06 22:08:52 +00:00

Resolve "Use environment variables in backend settings and web frontend config"

This commit is contained in:
Bram Wiepjes 2020-05-20 19:01:19 +00:00
parent 7fb0ba12a9
commit 36d29b1cde
10 changed files with 53 additions and 43 deletions

View file

@ -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

View file

@ -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'

View file

@ -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.

View file

@ -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',
},
}
}

View file

@ -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',
},
})

View file

@ -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

View file

@ -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

View file

@ -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,

View file

@ -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"
},

View file

@ -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"