Setting the baseURL in the axios module of Docker environment Nuxt

Problem Only axios after rendering the page doesn't work ...

First, using docker-compose, I created a nuxt development environment (frontend) and go API server environment (app) with a node image. You should now be able to resolve the container's address with app from the frontend container.

And implement axios in SSR: true environment,

I have set the baseURL, but I noticed that the baseURL has changed to localhost: 3000 (default). I was troubled by the phenomenon that $ store.dispatch written in methods after page rendering did not work even though the process called before page rendering (written by acyn fetch ()) worked correctly.

  axios: {
    baseURL: 'http://app:8080',
    proxy: true,
  proxy: {
    '/api': '/'
methods: { 
    axiosFunc() {  //This doesn't work 404 error
        const payload = {....}
        this.$store.dispatch('.....', payload)
async fetch({store}) { //Move over here
    const payload = {....}
    await store.dispatch('.....', payload)


I can guess the cause a little, but after all it seems that it has changed due to the communication relationship with the server before and after page rendering. And I found the blog below.

Since the fetch side that executes axios in SSR (container) runs on the baseURL and the function defined in methods is called on the browser side, it was necessary to set the browserBaseURL and switch the endpoint.

Also, it seems that the browser does not have the ability to trace the address by container name.


Put each container in a common network,

browserBaseURL: "http://app:8080",

I was able to move it safely by specifying.

Recommended Posts

Setting the baseURL in the axios module of Docker environment Nuxt
SSL in the local environment of Docker / Rails / puma
Install by specifying the version of Django in the Docker environment
Japanese setting of mysql in Docker container
Run Redmine in the local environment of Windows10 Pro-Use Docker Desktop for Windows
Self-hosting with Docker of AuteMuteUs in Windows environment
Improve the performance of your Docker development environment
Support out of support in docker environment using centos6
Docker the development environment of Ruby on Rails project
[Java] Get the file in the jar regardless of the environment
How to install Docker in the local environment of an existing Rails application [Rails 6 / MySQL 8]
A memorandum of the environment variable "JAVA_HOME" path setting procedure
Docker monitoring-explaining the basics of basics-
I tried to build the environment of WSL2 + Docker + VSCode
802.1X authentication to the network of Bonding setting in CentOS7
[Introduction] Setting up GridDB Community Edition in the CentOS container of Docker Desktop for the first time
What Docker beginners did before setting up the nginx learning environment
Use MailHog for checking emails in the development environment (using Docker)
Examine the system information of AWS Lambda operating environment in Java
I tried to build the environment of PlantUML Server with Docker
Build a browser test environment using Capybara in the Docker development environment
Install lsb_release from the command line when lsb_release fails in docker environment
Install laravel/Dusk in docker environment (laravel6)
Hit the Docker API in Rust
Order of processing in the program
Setting project environment variables in intelliJ
Check MySQL logs in Docker environment
[Rails & Docker & MySQL environment construction] Could not find gem ‘mysql2 (> = 0.4.4, <0.6.0)’ in any of the gem sources listed in your Gemfile.
How to execute with commands of normal development language in Docker development environment
I had to lower the PHP version in Docker + Composer + Laravel environment
Alert slack with alert manager in Docker environment
Put Kanban in Docker of Raspberry Pi 3
[Docker] Use environment variables in Nginx conf
The identity of params [: id] in rails
The story of updating SonarQube's Docker Container
Use docker in proxy environment on ubuntu 20.04.1
Scraping with puppeteer in Nuxt on Docker.
Edit Mysql with commands in Docker environment
The story of AppClip support in Anyca
Creating a Servlet in the Liberty environment
Show Better Errors in Rails + Docker environment
The story of writing Java in Emacs
Try the Docker environment on AWS ECS
[Rails] Reset the database in the production environment
Display the background image in the production environment
Write the movement of Rakefile in the runbook
Prepare Nuxt (web) + Laravel (API) development environment in the same repository using docker-compose
Procedure for introducing Docker into the development environment of existing Rails applications [Rails, MySQL, Docker]
Introduce Docker to the development environment and test environment of existing Rails and MySQL applications
Set the source of the library set as a dependency in IntelliJ as a separate module of the project
Let's refer to C ++ in the module of AndroidStudio other project (Java / kotlin)
How to set environment variables in the properties file of Spring boot application
What to do when ‘Could not find’ in any of the sources appears in the development environment with Docker × Rails × RSpec
About the solution of the error that occurred when trying to create a Japanese file of devise in the Docker development environment