diff --git a/nuxt.config.js b/nuxt.config.js index b763fa877..bc5f3d184 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -1,5 +1,5 @@ const pkg = require('./package') -const envWhitelist = ['NODE_ENV', 'BACKEND_URL', 'MAINTENANCE'] +const envWhitelist = ['NODE_ENV', 'MAINTENANCE'] const dev = process.env.NODE_ENV !== 'production' module.exports = { @@ -100,15 +100,39 @@ module.exports = { ** Nuxt.js modules */ modules: [ - '@nuxtjs/apollo', ['@nuxtjs/dotenv', { only: envWhitelist }], - ['nuxt-env', { keys: envWhitelist }] + ['nuxt-env', { keys: envWhitelist }], + '@nuxtjs/apollo', + '@nuxtjs/axios' ], + /* + ** Axios module configuration + */ + axios: { + // See https://github.com/nuxt-community/axios-module#options + debug: dev, + proxy: true + }, + proxy: { + '/api': { + // make this configurable (nuxt-dotenv) + target: process.env.BACKEND_URL || 'http://localhost:4000', + pathRewrite: { '^/api': '' }, + toProxy: true, // cloudflare needs that + changeOrigin: true, + headers: { + Accept: 'application/json', + 'X-UI-Request': true, + 'X-API-TOKEN': process.env.BACKEND_TOKEN || 'NULL' + } + } + }, + // Give apollo module options apollo: { - // tokenName: 'yourApolloTokenName', // optional, default: apollo-token - tokenExpires: 1, // optional, default: 7 (days) + tokenName: 'human-connection-token', // optional, default: apollo-token + tokenExpires: 3, // optional, default: 7 (days) // includeNodeModules: true, // optional, default: false (this includes graphql-tag for node_modules folder) // optional errorHandler(error) { diff --git a/package.json b/package.json index c33c4ec8a..261f150be 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ }, "dependencies": { "@nuxtjs/apollo": "^4.0.0-rc3", + "@nuxtjs/axios": "^5.3.6", "@nuxtjs/dotenv": "^1.3.0", "accounting": "^0.4.1", "cross-env": "^5.2.0", diff --git a/pages/login.vue b/pages/login.vue index 83818a837..3bb4d6c89 100644 --- a/pages/login.vue +++ b/pages/login.vue @@ -96,7 +96,7 @@ export default { try { await this.$store.dispatch('auth/login', { ...this.form }) this.$toast.success('You are logged in!') - this.$router.replace('/') + this.$router.replace(this.$route.query.path || '/') } catch (err) { this.$toast.error(err.message) } diff --git a/plugins/apollo-config.js b/plugins/apollo-config.js index 866d3ee92..db04e3406 100644 --- a/plugins/apollo-config.js +++ b/plugins/apollo-config.js @@ -1,7 +1,6 @@ export default function({ app }) { - const backendUrl = app.$env.BACKEND_URL || 'http://localhost:4000' return { - httpEndpoint: backendUrl, + httpEndpoint: '/api', httpLinkOptions: { credentials: 'same-origin' }, diff --git a/yarn.lock b/yarn.lock index 8b38d028a..e050b1af7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -693,6 +693,16 @@ vue-apollo "^3.0.0-beta.25" vue-cli-plugin-apollo "^0.17.0" +"@nuxtjs/axios@^5.3.6": + version "5.3.6" + resolved "https://registry.yarnpkg.com/@nuxtjs/axios/-/axios-5.3.6.tgz#1bad5af6e30977809cddd5248dd3b41271d1dc14" + integrity sha512-kxtiHW1QCYHaztKEkBnqH/GQoQoVubHdBWMC9+X0cVaA3AwOFsGI3Ef4/dSX8coSto7D+nV8LH3rVjbaFT+KUg== + dependencies: + "@nuxtjs/proxy" "^1.3.0" + axios "^0.18.0" + axios-retry "^3.1.1" + consola "^1.4.4" + "@nuxtjs/babel-preset-app@^0.7.0": version "0.7.0" resolved "https://registry.yarnpkg.com/@nuxtjs/babel-preset-app/-/babel-preset-app-0.7.0.tgz#b208a95e0a053259c29b99a9e4ca9ea2604dbdd2" @@ -732,6 +742,14 @@ esm "^3.0.79" node-fetch "^2.2.0" +"@nuxtjs/proxy@^1.3.0": + version "1.3.1" + resolved "https://registry.yarnpkg.com/@nuxtjs/proxy/-/proxy-1.3.1.tgz#7d76179aff321491f126d6560434579a4dc7a89a" + integrity sha512-agcTJVRCY0XfZcGV573bdIQLsg9fr5p6zikpxtUzR3xywdUBJ+JMKAiz3ew15bOZGK8lVS8u/PBmZ33iEhr3rg== + dependencies: + consola "^1.4.4" + http-proxy-middleware "^0.19.0" + "@nuxtjs/youch@^4.2.3": version "4.2.3" resolved "https://registry.yarnpkg.com/@nuxtjs/youch/-/youch-4.2.3.tgz#36f8b22df5a0efaa81373109851e1d857aca6bed" @@ -1547,6 +1565,21 @@ aws4@^1.6.0, aws4@^1.8.0: version "1.8.0" resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f" +axios-retry@^3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/axios-retry/-/axios-retry-3.1.1.tgz#88d2971f671a9023b21d887c5dcac6c54f332cde" + integrity sha512-BeNOxa/CBQQLa9gVuMta1oWIhbL6UETKBfAmFjOXwiBxgcmrDBVVwz/gKZTpzKJlVjmi5DeYC+lP5Ng7ssc1pg== + dependencies: + is-retry-allowed "^1.1.0" + +axios@^0.18.0: + version "0.18.0" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.18.0.tgz#32d53e4851efdc0a11993b6cd000789d70c05102" + integrity sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI= + dependencies: + follow-redirects "^1.3.0" + is-buffer "^1.1.5" + babel-code-frame@^6.26.0: version "6.26.0" resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b" @@ -2828,6 +2861,16 @@ consola@^1.4.3: lodash "^4.17.5" std-env "^1.1.0" +consola@^1.4.4: + version "1.4.5" + resolved "https://registry.yarnpkg.com/consola/-/consola-1.4.5.tgz#09732d07cb50af07332e54e0f42fafb92b962c4a" + integrity sha512-movqq3MbyXbSf7cG/x+EbO3VjKQVZPB/zeB5+lN1TuBYh9BWDemLQca9P+a4xpO4lXva9rz+Bd8XyqlH136Lww== + dependencies: + chalk "^2.3.2" + figures "^2.0.0" + lodash "^4.17.5" + std-env "^1.1.0" + console-browserify@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/console-browserify/-/console-browserify-1.1.0.tgz#f0241c45730a9fc6323b206dbf38edc741d0bb10" @@ -3236,6 +3279,13 @@ debug@2.6.9, debug@^2.1.2, debug@^2.2.0, debug@^2.3.3, debug@^2.6.8, debug@^2.6. dependencies: ms "2.0.0" +debug@=3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261" + integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g== + dependencies: + ms "2.0.0" + debug@^3.1.0: version "3.2.5" resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.5.tgz#c2418fbfd7a29f4d4f70ff4cea604d4b64c46407" @@ -3795,7 +3845,7 @@ event-stream@~3.3.0: stream-combiner "^0.2.2" through "^2.3.8" -eventemitter3@^3.1.0: +eventemitter3@^3.0.0, eventemitter3@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-3.1.0.tgz#090b4d6cdbd645ed10bf750d4b5407942d7ba163" @@ -4168,6 +4218,13 @@ flush-write-stream@^1.0.0: inherits "^2.0.1" readable-stream "^2.0.4" +follow-redirects@^1.0.0, follow-redirects@^1.3.0: + version "1.5.10" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.10.tgz#7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a" + integrity sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ== + dependencies: + debug "=3.1.0" + for-in@^0.1.3: version "0.1.8" resolved "https://registry.yarnpkg.com/for-in/-/for-in-0.1.8.tgz#d8773908e31256109952b1fdb9b3fa867d2775e1" @@ -4678,6 +4735,25 @@ http-errors@1.6.3, http-errors@~1.6.2, http-errors@~1.6.3: setprototypeof "1.1.0" statuses ">= 1.4.0 < 2" +http-proxy-middleware@^0.19.0: + version "0.19.1" + resolved "https://registry.yarnpkg.com/http-proxy-middleware/-/http-proxy-middleware-0.19.1.tgz#183c7dc4aa1479150306498c210cdaf96080a43a" + integrity sha512-yHYTgWMQO8VvwNS22eLLloAkvungsKdKTLO8AJlftYIKNfJr3GK3zK0ZCfzDDGUBttdGc8xFy1mCitvNKQtC3Q== + dependencies: + http-proxy "^1.17.0" + is-glob "^4.0.0" + lodash "^4.17.11" + micromatch "^3.1.10" + +http-proxy@^1.17.0: + version "1.17.0" + resolved "https://registry.yarnpkg.com/http-proxy/-/http-proxy-1.17.0.tgz#7ad38494658f84605e2f6db4436df410f4e5be9a" + integrity sha512-Taqn+3nNvYRfJ3bGvKfBSRwy1v6eePlm3oc/aWVxZp57DQr5Eq3xhKJi7Z4hZpS8PC3H4qI+Yly5EmFacGuA/g== + dependencies: + eventemitter3 "^3.0.0" + follow-redirects "^1.0.0" + requires-port "^1.0.0" + http-signature@~1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/http-signature/-/http-signature-1.2.0.tgz#9aecd925114772f3d95b65a60abb8f7c18fbace1" @@ -5090,7 +5166,7 @@ is-resolvable@^1.0.0, is-resolvable@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/is-resolvable/-/is-resolvable-1.1.0.tgz#fb18f87ce1feb925169c9a407c19318a3206ed88" -is-retry-allowed@^1.0.0: +is-retry-allowed@^1.0.0, is-retry-allowed@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/is-retry-allowed/-/is-retry-allowed-1.1.0.tgz#11a060568b67339444033d0125a61a20d564fb34" @@ -8127,6 +8203,11 @@ require-uncached@^1.0.3: caller-path "^0.1.0" resolve-from "^1.0.0" +requires-port@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff" + integrity sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8= + resolve-cwd@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/resolve-cwd/-/resolve-cwd-2.0.0.tgz#00a9f7387556e27038eae232caa372a6a59b665a"