Fetch API failed in Docker, Setting CORS middleware doesn't work

I figured it out myself. Once I run docker-compose on my server, I change the fetch link from http://localhost:1337/api/posts to http://{ip}:1337/api/posts

And it works.