2

I have a config file with API URL under the path "src/config.js":

const API_URL = 'https://some-url-here.com'

export default {
  API_URL: API_URL
}

And a Dockerfile:

# build stage
FROM node:9.11.1-alpine as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build

# production stage
FROM nginx:1.13.12-alpine as production-stage
COPY --from=build-stage /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

How can i make that API_URL available to docker, so devops could change that url?

2
  • You can define environment variables inside Dockerfile; ENV API_URL = some_url Then in your src/config.js file you can access it via process.env.API_URL Commented Aug 27, 2018 at 14:36
  • if i set process.env.API_URL and in "config/dev.env.js" i'll add module.exports = merge(prodEnv, { API_URL: '"https://url.com"' }) Commented Aug 28, 2018 at 3:32

1 Answer 1

2

Using Vue-cli 2.9, you can set ENV variables in a "config" directory.

For example: "config/dev.env.js":

module.exports = merge(prodEnv, {
  NODE_ENV: '"development"',
  API_URL: '"https://server.com"'
})

Then you can use it in your client :

const API_URL = process.env.API_URL
export default {
  API_URL: API_URL,
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.