Skip to content
This repository was archived by the owner on Nov 28, 2020. It is now read-only.

Commit 49d229b

Browse files
committed
Make @nuxtjs/axios to use NUXT_ENV_
1 parent 33fbee2 commit 49d229b

File tree

5 files changed

+40
-9
lines changed

5 files changed

+40
-9
lines changed

nuxt.config.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import NuxtConfiguration from "@nuxt/config"
22

3+
// https://nuxtjs.org/api/configuration-env/
4+
const apiBaseUrl = process.env.NUXT_ENV_API_URL || "https://api.hnpwa.com/v0"
5+
36
const isDev = process.env.NODE_ENV !== "production"
47

58
const config: NuxtConfiguration = {
@@ -40,13 +43,17 @@ const config: NuxtConfiguration = {
4043
theme_color: "#188269"
4144
},
4245
modules: ["@nuxtjs/pwa", "@nuxtjs/component-cache", "@nuxtjs/axios"],
46+
env: {
47+
apiBaseUrl
48+
},
4349
axios: {
4450
debug: isDev,
45-
proxy: true
51+
proxy: true,
52+
baseURL: apiBaseUrl
4653
},
4754
proxy: {
4855
"/api": {
49-
target: "https://api.hnpwa.com/v0/",
56+
target: apiBaseUrl,
5057
pathRewrite: {
5158
"^/api/": ""
5259
}

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,17 @@
4747
"node": ">=8.0"
4848
},
4949
"dependencies": {
50-
"@nuxtjs/axios": "^5.5.2",
50+
"@nuxtjs/axios": "^5.3.6",
5151
"@nuxtjs/component-cache": "1.1.4",
5252
"@nuxtjs/pwa": "2.6.0",
5353
"apicache": "1.2.3",
5454
"express": "4.16.4",
55-
"nuxt": "^2.7.1",
55+
"nuxt-start": "^2.7.1",
5656
"ts-node": "^8.2.0",
5757
"vue-property-decorator": "^8.1.1"
5858
},
5959
"devDependencies": {
60+
"nuxt": "^2.7.1",
6061
"@nuxt/typescript": "^2.7.1",
6162
"@types/jest": "^24.0.13",
6263
"@vue/test-utils": "^1.0.0-beta.28",
@@ -71,6 +72,11 @@
7172
"vue-jest": "^3.0.4",
7273
"tslint": "^5.0.0"
7374
},
75+
"browserslist": [
76+
"last 1 version",
77+
"> 1%",
78+
"IE 11"
79+
],
7480
"jest": {
7581
"moduleFileExtensions": [
7682
"js",

store/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import Vue from "vue"
55
import { validFeeds } from "~/common/api"
66
import { lazy } from "~/common/utils"
77
// import { CancelToken } from "axios"
8-
const baseUrl = "/api" // https://api.hnpwa.com/v0" // "/api"
8+
9+
// process.env.NUXT_ENV_API_URL + apiBasePath
10+
// 'https://api.hnpwa.com/v0' + '/api'
11+
const apiBasePath = "/api"
912

1013
interface Dictionary<T> {
1114
[key: string]: T
@@ -133,7 +136,7 @@ const actions: ActionTree<IRootState, any> = {
133136
commit("SET_ITEMS", { items })
134137
},
135138
() =>
136-
(this as any).$axios.$get(`${baseUrl}/${feed}/${page}.json`, {
139+
(this as any).$axios.$get(`${apiBasePath}/${feed}/${page}.json`, {
137140
cancelToken:
138141
(this as any).feedCancelSource &&
139142
(this as any).feedCancelSource.token
@@ -145,15 +148,15 @@ const actions: ActionTree<IRootState, any> = {
145148
FETCH_ITEM({ commit, state }, { id }) {
146149
return lazy(
147150
item => commit("SET_ITEM", { item }),
148-
() => (this as any).$axios.$get(`${baseUrl}/item/${id}.json`),
151+
() => (this as any).$axios.$get(`${apiBasePath}/item/${id}.json`),
149152
Object.assign({ id, loading: true, comments: [] }, state.items[id])
150153
)
151154
},
152155

153156
FETCH_USER({ state, commit }, { id }) {
154157
return lazy(
155158
user => commit("SET_USER", { id, user }),
156-
() => (this as any).$axios.$get(`${baseUrl}/user/${id}.json`),
159+
() => (this as any).$axios.$get(`${apiBasePath}/user/${id}.json`),
157160
Object.assign({ id, loading: true }, state.users[id])
158161
)
159162
}

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"types": [
2828
"@types/jest",
2929
"@types/node",
30+
"@nuxtjs/axios",
3031
"@nuxt/vue-app"
3132
]
3233
}

yarn.lock

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@
14741474
webpack-node-externals "^1.7.2"
14751475
webpackbar "^3.2.0"
14761476

1477-
"@nuxtjs/axios@^5.5.2":
1477+
"@nuxtjs/axios@^5.3.6":
14781478
version "5.5.2"
14791479
resolved "https://registry.yarnpkg.com/@nuxtjs/axios/-/axios-5.5.2.tgz#b6447bb12707b56b16b942ae6c737a0b051cecba"
14801480
integrity sha512-S5+IkUjCSSFeMVZp/JAzjoit9P7Di2QM4beAlFbHXbOEG+/vSaZReW8l817u9WC6nuKa3x6HhZfWD3tJDTvljg==
@@ -6927,6 +6927,20 @@ number-is-nan@^1.0.0:
69276927
resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d"
69286928
integrity sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=
69296929

6930+
nuxt-start@^2.7.1:
6931+
version "2.7.1"
6932+
resolved "https://registry.yarnpkg.com/nuxt-start/-/nuxt-start-2.7.1.tgz#84b03164b0013bcfbc2b90432c1140bb7ee560e5"
6933+
integrity sha512-IRwTg3Uy33Njmg+geQWinfUeJ2qd+n1VqkgZEqN+80XKkw/LTW40rTm3LKCIVaflbX7Ekc8jI8YJ+M38egPWgQ==
6934+
dependencies:
6935+
"@nuxt/cli" "2.7.1"
6936+
"@nuxt/core" "2.7.1"
6937+
node-fetch "^2.5.0"
6938+
vue "^2.6.10"
6939+
vue-meta "^1.6.0"
6940+
vue-no-ssr "^1.1.1"
6941+
vue-router "^3.0.6"
6942+
vuex "^3.1.1"
6943+
69306944
nuxt@^2.7.1:
69316945
version "2.7.1"
69326946
resolved "https://registry.yarnpkg.com/nuxt/-/nuxt-2.7.1.tgz#fa1caf0db71a9c99046aea7d5829c3de63b4b31c"

0 commit comments

Comments
 (0)