diff options
| author | Pitu <[email protected]> | 2019-03-29 00:35:22 +0900 |
|---|---|---|
| committer | Pitu <[email protected]> | 2019-03-29 00:35:22 +0900 |
| commit | 8905f2e7a7096e8567e1d1871af62f0842303dfc (patch) | |
| tree | f0b1028ab479716b2dbe26b538935b58d5f7f82c | |
| parent | Turns out we were using the wrong cookieparser (diff) | |
| download | host.fuwn.me-8905f2e7a7096e8567e1d1871af62f0842303dfc.tar.xz host.fuwn.me-8905f2e7a7096e8567e1d1871af62f0842303dfc.zip | |
Added axios package
| -rw-r--r-- | nuxt.config.js | 8 | ||||
| -rw-r--r-- | package.json | 3 | ||||
| -rw-r--r-- | src/site/plugins/axios.js | 29 | ||||
| -rw-r--r-- | src/site/plugins/vue-axios.js | 6 | ||||
| -rw-r--r-- | src/site/store/index.js | 22 | ||||
| -rw-r--r-- | yarn.lock | 71 |
6 files changed, 115 insertions, 24 deletions
diff --git a/nuxt.config.js b/nuxt.config.js index 6574d3d..42ccc4e 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -54,7 +54,7 @@ export default { ] }, plugins: [ - '~/plugins/vue-axios', + '~/plugins/axios', '~/plugins/buefy', '~/plugins/v-clipboard', '~/plugins/vue-isyourpasswordsafe', @@ -64,6 +64,12 @@ export default { { path: '/', handler: serveStatic(path.join(__dirname, 'uploads')) } ], css: [], + modules: [ + '@nuxtjs/axios' + ], + axios: { + baseURL: `${process.env.DOMAIN}${process.env.ROUTE_PREFIX}` + }, build: { extractCSS: true, postcss: [ diff --git a/package.json b/package.json index fb1ad6a..4146a70 100644 --- a/package.json +++ b/package.json @@ -30,8 +30,8 @@ "node": ">=8.0.0" }, "dependencies": { + "@nuxtjs/axios": "^5.4.1", "adm-zip": "^0.4.13", - "axios": "^0.18.0", "bcrypt": "^3.0.4", "body-parser": "^1.18.3", "buefy": "0.6.3", @@ -47,7 +47,6 @@ "file-saver": "^2.0.1", "fluent-ffmpeg": "^2.1.2", "fs-jetpack": "^2.2.2", - "fuse.js": "^3.4.0", "helmet": "^3.15.1", "imagesloaded": "^4.1.4", "jsonwebtoken": "^8.5.0", diff --git a/src/site/plugins/axios.js b/src/site/plugins/axios.js new file mode 100644 index 0000000..5a169b2 --- /dev/null +++ b/src/site/plugins/axios.js @@ -0,0 +1,29 @@ +/* +import Vue from 'vue'; +import axios from 'axios'; +import VueAxios from 'vue-axios'; + +Vue.use(VueAxios, axios); +Vue.axios.defaults.headers.common.Accept = 'application/vnd.lolisafe.json'; +*/ + +export default function({ $axios, redirect }) { + $axios.onRequest(config => { + console.log(`Making request to > /${config.url}`); + }); + $axios.setHeader('accept', 'application/vnd.lolisafe.json'); + + $axios.onError(error => { + // console.log('====='); + console.log(error); + // console.log('====='); + /* + $toast.open({ + duration: 2500, + message: 'testing', + position: 'is-bottom', + type: error ? 'is-danger' : 'is-success' + }); + */ + }); +} diff --git a/src/site/plugins/vue-axios.js b/src/site/plugins/vue-axios.js deleted file mode 100644 index 41f026f..0000000 --- a/src/site/plugins/vue-axios.js +++ /dev/null @@ -1,6 +0,0 @@ -import Vue from 'vue'; -import axios from 'axios'; -import VueAxios from 'vue-axios'; - -Vue.use(VueAxios, axios); -Vue.axios.defaults.headers.common.Accept = 'application/vnd.lolisafe.json'; diff --git a/src/site/store/index.js b/src/site/store/index.js index 6a05622..13e49c3 100644 --- a/src/site/store/index.js +++ b/src/site/store/index.js @@ -1,5 +1,7 @@ +/* import Vue from 'vue'; import axios from 'axios'; +*/ const cookieparser = process.server ? require('cookieparser') : null; @@ -27,7 +29,6 @@ export const mutations = { state.token = null; return; } - setAuthorizationHeader(payload); state.token = payload; }, config(state, payload) { @@ -36,7 +37,7 @@ export const mutations = { }; export const actions = { - async nuxtServerInit({ commit }, { req }) { + async nuxtServerInit({ commit }, { app, req }) { commit('config', { version: process.env.npm_package_version, URL: process.env.DOMAIN, @@ -56,9 +57,11 @@ export const actions = { commit('loggedIn', true); commit('token', token); - const res = await axios.get(`${this.config.baseURL}/verify`); - if (!res || !res.data.user); - commit('user', res.data.user); + app.$axios.setToken(token, 'Bearer'); + + const data = await this.$axios.$get(`verify`); + if (!data || !data.user); + commit('user', data.user); } catch (error) { // TODO: Deactivate this on production console.error(error); @@ -69,9 +72,10 @@ export const actions = { commit('user', null); commit('loggedIn', false); } + }, + login({ commit }, { app, token, user }) { + commit('token', token); + commit('user', user); + commit('loggedIn', true); } }; - -const setAuthorizationHeader = payload => { - Vue.axios.defaults.headers.common.Authorization = payload ? `Bearer ${payload}` : ''; -}; @@ -890,6 +890,24 @@ webpack-node-externals "^1.7.2" webpackbar "^3.1.5" +"@nuxtjs/axios@^5.4.1": + version "5.4.1" + resolved "https://registry.yarnpkg.com/@nuxtjs/axios/-/axios-5.4.1.tgz#8dbc841e939c082271f7053edc1180bf5a441ee3" + integrity sha512-SvN6Ixs9d2AHdaB8PF4ZXr9azg4r3ynaomtr71+wMox3EEFfZHBQmAFz6lOY/CqbLRlJqYVDPKPvfIcSnngktw== + dependencies: + "@nuxtjs/proxy" "^1.3.3" + axios "^0.18.0" + axios-retry "^3.1.2" + consola "^2.5.6" + +"@nuxtjs/proxy@^1.3.3": + version "1.3.3" + resolved "https://registry.yarnpkg.com/@nuxtjs/proxy/-/proxy-1.3.3.tgz#3de3d9f073e8e57167168100940be2a824a220e0" + integrity sha512-ykpCUdOqPOH79mQG30QfWZmbRD8yjTD+TTSBbwow5GkROUQEtXw+HE+q6i+YFpuChvgJNbwVrXdZ3YmfXbZtTw== + dependencies: + consola "^2.5.6" + http-proxy-middleware "^0.19.1" + "@nuxtjs/youch@^4.2.3": version "4.2.3" resolved "https://registry.yarnpkg.com/@nuxtjs/youch/-/youch-4.2.3.tgz#36f8b22df5a0efaa81373109851e1d857aca6bed" @@ -1446,6 +1464,13 @@ aws4@^1.8.0: resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f" integrity sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ== +axios-retry@^3.1.2: + version "3.1.2" + resolved "https://registry.yarnpkg.com/axios-retry/-/axios-retry-3.1.2.tgz#4f4dcbefb0b434e22b72bd5e28a027d77b8a3458" + integrity sha512-+X0mtJ3S0mmia1kTVi1eA3DAC+oWnT2A29g3CpkzcBPMT6vJm+hn/WiV9wPt/KXLHVmg5zev9mWqkPx7bHMovg== + 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" @@ -2201,6 +2226,11 @@ consola@^2.0.0-1, consola@^2.3.0, consola@^2.3.2: std-env "^2.2.1" string-width "^3.0.0" +consola@^2.5.6: + version "2.5.6" + resolved "https://registry.yarnpkg.com/consola/-/consola-2.5.6.tgz#5ce14dbaf6f5b589c8a258ef80ed97b752fa57d5" + integrity sha512-DN0j6ewiNWkT09G3ZoyyzN3pSYrjxWcx49+mHu+oDI5dvW5vzmyuzYsqGS79+yQserH9ymJQbGzeqUejfssr8w== + console-browserify@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/console-browserify/-/console-browserify-1.1.0.tgz#f0241c45730a9fc6323b206dbf38edc741d0bb10" @@ -3230,6 +3260,11 @@ ev-emitter@^1.0.0: resolved "https://registry.yarnpkg.com/ev-emitter/-/ev-emitter-1.1.1.tgz#8f18b0ce5c76a5d18017f71c0a795c65b9138f2a" integrity sha512-ipiDYhdQSCZ4hSbX4rMW+XzNKMD1prg/sTvoVmSLkuQ1MVlwjJQQA+sW8tMYR3BLUr9KjodFV4pvzunvRhd33Q== +eventemitter3@^3.0.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-3.1.0.tgz#090b4d6cdbd645ed10bf750d4b5407942d7ba163" + integrity sha512-ivIvhpq/Y0uSjcHDcOIccjmYjGLcP09MFGE7ysAwkAvkXfpZlC985pH2/ui64DKazbTW/4kN3yqozUxlXzI6cA== + events@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/events/-/events-3.0.0.tgz#9a0a0dfaf62893d92b875b8f2698ca4114973e88" @@ -3599,7 +3634,7 @@ flush-write-stream@^1.0.0: inherits "^2.0.3" readable-stream "^2.3.6" -follow-redirects@^1.3.0: +follow-redirects@^1.0.0, follow-redirects@^1.3.0: version "1.7.0" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.7.0.tgz#489ebc198dc0e7f64167bd23b03c4c19b5784c76" integrity sha512-m/pZQy4Gj287eNy94nivy5wchN3Kp+Q5WgUPNy5lJSZ3sgkVKSYV/ZChMAQVIgx1SqfZ2zBZtPA2YlXIWxxJOQ== @@ -3744,11 +3779,6 @@ functional-red-black-tree@^1.0.1: resolved "https://registry.yarnpkg.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327" integrity sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc= -fuse.js@^3.4.0: - version "3.4.2" - resolved "https://registry.yarnpkg.com/fuse.js/-/fuse.js-3.4.2.tgz#d7a638c436ecd7b9c4c0051478c09594eb956212" - integrity sha512-WVbrm+cAxPtyMqdtL7cYhR7aZJPhtOfjNClPya8GKMVukKDYs7pEnPINeRVX1C9WmWgU8MdYGYbUPAP2AJXdoQ== - gauge@~2.7.3: version "2.7.4" resolved "https://registry.yarnpkg.com/gauge/-/gauge-2.7.4.tgz#2c03405c7538c39d7eb37b317022e325fb018bf7" @@ -4147,6 +4177,25 @@ [email protected], http-errors@~1.6.2, http-errors@~1.6.3: setprototypeof "1.1.0" statuses ">= 1.4.0 < 2" +http-proxy-middleware@^0.19.1: + 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" @@ -4553,6 +4602,11 @@ is-resolvable@^1.0.0: resolved "https://registry.yarnpkg.com/is-resolvable/-/is-resolvable-1.1.0.tgz#fb18f87ce1feb925169c9a407c19318a3206ed88" integrity sha512-qgDYXFSR5WvEfuS5dMj6oTMEbrrSaM0CrFk2Yiq/gXnBvD9pMa2jGXxyhGLfvhZpuMZe18CJpFxAt3CRs42NMg== +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" + integrity sha1-EaBgVotnM5REAz0BJaYaINVk+zQ= + is-stream@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44" @@ -7323,6 +7377,11 @@ require-main-filename@^1.0.1: resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-1.0.1.tgz#97f717b69d48784f5f526a6c5aa8ffdda055a4d1" integrity sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE= +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-dir@^1.0.0, resolve-dir@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/resolve-dir/-/resolve-dir-1.0.1.tgz#79a40644c362be82f26effe739c9bb5382046f43" |