Skip to content

Commit ee4a406

Browse files
committed
Complete rewrite of configuration
- no bash scripts * error prone * platform dependent) - replace `dotenv` with `config` * less redundancy, merge config with defaults * consistency with API repository * configurable in docker container
1 parent 44d7203 commit ee4a406

19 files changed

Lines changed: 53 additions & 193 deletions

.env.tmp

Lines changed: 0 additions & 35 deletions
This file was deleted.

entrypoint.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.

middleware/authenticated.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { isEmpty } from 'lodash'
22

3-
export default async ({ store, route, redirect }) => {
4-
let publicPages = process.env.publicPages
3+
export default async ({ store, env, route, redirect }) => {
4+
let publicPages = env.publicPages
55
publicPages.push('auth-logout')
66
// only affect non public pages
77
if (publicPages.indexOf(route.name) >= 0) {

middleware/maintenance.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2-
export default async function ({ app, error, store, redirect, route }) {
2+
export default async function ({ app, env, error, store, redirect, route }) {
33
let isMaintenanceEnabled = false
4-
if (Boolean(app.$env.MAINTENANCE) === true) {
4+
if (Boolean(env.MAINTENANCE) === true) {
55
error({ statusCode: 503, message: 'Maintenance Mode' })
66
return
77
}

nuxt.config.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ module.exports = {
9393
}
9494
},
9595
plugins: [
96-
{src: '~/plugins/env.js'},
9796
{src: '~/plugins/debug.js', ssr: false},
9897
{src: '~/plugins/raven-client.js', ssr: false},
9998
{src: '~/plugins/api.js'},
@@ -112,8 +111,20 @@ module.exports = {
112111
{src: '~/plugins/open-page-in-modal.js', ssr: false}
113112
],
114113
modules: [
115-
'cookie-universal-nuxt',
116-
'@nuxtjs/dotenv'
114+
['@nuxtjs/dotenv', {
115+
only: [
116+
'WEBAPP_HOST',
117+
'WEBAPP_PORT',
118+
'WEBAPP_BASE_URL',
119+
'API_HOST',
120+
'API_PORT',
121+
'EMBED_API_URL',
122+
'SENTRY_DNS_PUBLIC',
123+
'MAPBOX_TOKEN',
124+
'MAINTENANCE',
125+
]
126+
}],
127+
'cookie-universal-nuxt'
117128
// '@nuxtjs/pwa'
118129
],
119130
router: {

package.json

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,17 @@
2727
"yarn": ">= 1.3.0"
2828
},
2929
"scripts": {
30-
"dev": "yarn dev:env && backpack dev",
31-
"dev:local": "sh scripts/run-local.sh",
32-
"dev:debug": "yarn dev:env && backpack dev --inspect-brk=9229",
33-
"dev:env": "sh scripts/on-dev.sh",
34-
"build": "yarn build:env && nuxt build && backpack build",
35-
"build:env": "sh scripts/on-build.sh",
36-
"start": "yarn start:env && node build/main.js",
37-
"start:pm2": "yarn start:env && pm2 start node build/main.js -n frontend -i 2 --attach",
38-
"start:env": "sh scripts/on-start.sh",
39-
"refresh": "rm -rf node_modules && yarn install && npm run dev",
30+
"clean": "rm -rf build/*",
31+
"dev": "backpack dev",
32+
"dev:debug": "backpack dev --inspect=0.0.0.0:9229",
33+
"build": "nuxt build && backpack build",
34+
"start": "node build/main.js",
35+
"start:pm2": "pm2 start node build/main.js -n frontend -i 2 --attach",
4036
"precommit": "yarn eslint",
4137
"eslint": "eslint --ext .js,.vue .",
4238
"styleguide": "vue-styleguidist server",
4339
"styleguide:build": "vue-styleguidist build",
4440
"test": "ava",
45-
"test:env": "sh scripts/on-dev.sh",
4641
"cypress:open": "cypress open",
4742
"cypress:run": "cypress run",
4843
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov"
@@ -52,7 +47,7 @@
5247
"@feathersjs/client": "^3.5.3",
5348
"@feathersjs/feathers": "^3.1.7",
5449
"@feathersjs/socketio": "^3.2.2",
55-
"@nuxtjs/dotenv": "~1.1.0",
50+
"@nuxtjs/dotenv": "^1.1.1",
5651
"@nuxtjs/pwa": "~2.0.5",
5752
"axios": "^0.18.0",
5853
"babel-eslint": "~8.2.5",

plugins/api.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import authentication from '@feathersjs/authentication-client'
55
import urlHelper from '~/helpers/urls'
66
import Vue from 'vue'
77

8-
export default ({app, store, redirect, router}) => {
8+
export default ({app, env, store, redirect, router}) => {
99
const authKey = 'feathers-jwt'
10-
const endpoint = urlHelper.buildEndpointURL(app.$env.API_HOST, { port: app.$env.API_PORT })
10+
const endpoint = urlHelper.buildEndpointURL(env.API_HOST, { port: env.API_PORT })
1111
const storage = {
1212
getItem: (key) => {
1313
const res = app.$cookies.get(key)
@@ -26,7 +26,7 @@ export default ({app, store, redirect, router}) => {
2626
},
2727
clear: () => {
2828
const res = app.$cookies.removeAll()
29-
if (process.env.NODE_ENV === 'development') {
29+
if (env.NODE_ENV === 'development') {
3030
console.log(`## STORAGE: clear()`, res)
3131
}
3232
return res
@@ -60,7 +60,7 @@ export default ({app, store, redirect, router}) => {
6060
all: [
6161
async (hook) => {
6262
// hook.accessToken = await api.passport.getJWT()
63-
if (process.env.NODE_ENV === 'development') {
63+
if (env.NODE_ENV === 'development') {
6464
console.log('# API:', `${hook.method} ${hook.path}`)
6565
console.info('data', hook.data)
6666
// console.log('# ' + hook.accessToken)
@@ -70,7 +70,7 @@ export default ({app, store, redirect, router}) => {
7070
]
7171
},
7272
async error (ctx) {
73-
if (process.env.NODE_ENV === 'development') {
73+
if (env.NODE_ENV === 'development') {
7474
console.log('####################')
7575
console.error(ctx.error)
7676
console.info('JWT TOKEN: ', app.$cookies.get(authKey))

plugins/env.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

plugins/i18n.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { debounce, isEmpty } from 'lodash'
44

55
import vuexI18n from 'vuex-i18n/dist/vuex-i18n.umd.js'
66

7-
export default ({ app, req, cookie, store }) => {
8-
const doDebug = process.env.NODE_ENV !== 'production'
7+
export default ({ app, env, req, cookie, store }) => {
8+
const doDebug = env.NODE_ENV !== 'production'
99
const key = 'locale'
1010

1111
const changeHandler = debounce((mutation, store) => {

plugins/raven-client.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import Vue from 'vue'
22
import Raven from 'raven-js'
33
import RavenVue from 'raven-js/plugins/vue'
44

5-
export default ({app}) => {
6-
if (process.browser && app.$env.SENTRY_DNS_PUBLIC) {
5+
export default ({env}) => {
6+
if (process.browser && env.SENTRY_DNS_PUBLIC) {
77
Raven
8-
.config(app.$env.SENTRY_DNS_PUBLIC, {
9-
release: app.$env.BUILD_DATE,
10-
environment: app.$env.NODE_ENV,
8+
.config(env.SENTRY_DNS_PUBLIC, {
9+
release: env.BUILD_DATE,
10+
environment: env.NODE_ENV,
1111
tags: {
12-
deployed: app.$env.DEPLOY_DATE,
12+
deployed: env.DEPLOY_DATE,
1313
client: true
1414
}
1515
})

0 commit comments

Comments
 (0)