Make api url configurable in index.html
This commit is contained in:
parent
1bad154da6
commit
d46faec23d
7 changed files with 17 additions and 15 deletions
|
@ -38,8 +38,8 @@ steps:
|
||||||
commands:
|
commands:
|
||||||
- yarn --frozen-lockfile
|
- yarn --frozen-lockfile
|
||||||
- yarn run lint
|
- yarn run lint
|
||||||
- "echo '{\"VIKUNJA_API_BASE_URL\": \"/api/v1/\"}' > /drone/src/public/config.json" # Override config
|
|
||||||
- yarn run build
|
- yarn run build
|
||||||
|
- sed -i 's/http\:\/\/localhost\:8080\/api\/v1/\/api\/v1/g' dist/index.html # Override the default api url used for developing
|
||||||
|
|
||||||
- name: static
|
- name: static
|
||||||
image: kolaente/zip
|
image: kolaente/zip
|
||||||
|
@ -112,8 +112,8 @@ steps:
|
||||||
commands:
|
commands:
|
||||||
- yarn --frozen-lockfile
|
- yarn --frozen-lockfile
|
||||||
- yarn run lint
|
- yarn run lint
|
||||||
- "echo '{\"VIKUNJA_API_BASE_URL\": \"/api/v1/\"}' > /drone/src/public/config.json" # Override config
|
|
||||||
- yarn run build
|
- yarn run build
|
||||||
|
- sed -i 's/http\:\/\/localhost\:8080\/api\/v1/\/api\/v1/g' dist/index.html # Override the default api url used for developing
|
||||||
|
|
||||||
- name: static
|
- name: static
|
||||||
image: kolaente/zip
|
image: kolaente/zip
|
||||||
|
|
|
@ -5,11 +5,12 @@ WORKDIR /build
|
||||||
|
|
||||||
COPY . ./
|
COPY . ./
|
||||||
|
|
||||||
# Override config
|
RUN \
|
||||||
RUN echo '{"VIKUNJA_API_BASE_URL": "/api/v1/"}' > /build/public/config.json && \
|
|
||||||
# Build the frontend
|
# Build the frontend
|
||||||
yarn install --frozen-lockfile && \
|
yarn install --frozen-lockfile && \
|
||||||
yarn run build
|
yarn run build && \
|
||||||
|
# Override config
|
||||||
|
sed -i 's/http\:\/\/localhost\:8080\/api\/v1/\/api\/v1/g' dist/index.html
|
||||||
|
|
||||||
# Stage 2: copy
|
# Stage 2: copy
|
||||||
FROM nginx
|
FROM nginx
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
{
|
|
||||||
"VIKUNJA_API_BASE_URL": "http://localhost:8080/api/v1/"
|
|
||||||
}
|
|
|
@ -25,5 +25,13 @@
|
||||||
</noscript>
|
</noscript>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
<!-- built files will be auto injected -->
|
<!-- built files will be auto injected -->
|
||||||
|
<script>
|
||||||
|
//
|
||||||
|
// This variable points the frontend to the api.
|
||||||
|
// It has to be the full url, including the last /api/v1 part and port.
|
||||||
|
// You can change this if your api is not reachable on the same port as the frontend.
|
||||||
|
window.API_URL = 'http://localhost:8080/api/v1'
|
||||||
|
//
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
let config = require('../../public/config.json')
|
|
||||||
|
|
||||||
export const HTTP = axios.create({
|
export const HTTP = axios.create({
|
||||||
baseURL: config.VIKUNJA_API_BASE_URL
|
baseURL: window.API_URL
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import AbstractModel from './abstractModel'
|
import AbstractModel from './abstractModel'
|
||||||
import config from '../../public/config'
|
|
||||||
|
|
||||||
export default class UserModel extends AbstractModel {
|
export default class UserModel extends AbstractModel {
|
||||||
constructor(data) {
|
constructor(data) {
|
||||||
|
@ -19,6 +18,6 @@ export default class UserModel extends AbstractModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
getAvatarUrl(size = 50) {
|
getAvatarUrl(size = 50) {
|
||||||
return `${config.VIKUNJA_API_BASE_URL}${this.username}/avatar?size=${size}`
|
return `${window.API_URL}${this.username}/avatar?size=${size}`
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,8 +2,6 @@ import axios from 'axios'
|
||||||
import {reduce, replace} from 'lodash'
|
import {reduce, replace} from 'lodash'
|
||||||
import { objectToSnakeCase } from '../helpers/case'
|
import { objectToSnakeCase } from '../helpers/case'
|
||||||
|
|
||||||
let config = require('../../public/config.json')
|
|
||||||
|
|
||||||
export default class AbstractService {
|
export default class AbstractService {
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
|
@ -33,7 +31,7 @@ export default class AbstractService {
|
||||||
*/
|
*/
|
||||||
constructor(paths) {
|
constructor(paths) {
|
||||||
this.http = axios.create({
|
this.http = axios.create({
|
||||||
baseURL: config.VIKUNJA_API_BASE_URL,
|
baseURL: window.API_URL,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue