DEV Community

Discussion on: JavaScript CRUD Rest API using Nodejs, Express, Sequelize, Postgres, Docker and Docker Compose

Collapse
 
francescoxx profile image
Francesco Ciulla

try docker ps -a. can you see the containers up and running?

Collapse
 
edwardfernando profile image
Edward Fernando
➜  ~ docker ps -a
CONTAINER ID   IMAGE               COMMAND                  CREATED        STATUS          PORTS                              NAMES
d3f626718969   efs/node_live_app   "docker-entrypoint.s…"   15 hours ago   Up 39 seconds   3000/tcp, 0.0.0.0:3333->3333/tcp   node_app
3c423213aeff   postgres:12         "docker-entrypoint.s…"   15 hours ago   Up 15 hours     0.0.0.0:5432->5432/tcp             node_db
Enter fullscreen mode Exit fullscreen mode

It is actually running

Thread Thread
 
edwardfernando profile image
Edward Fernando

in the index.js, i tried to commented out these lines and it is working now:

// app.use((req, res, next) => {
//     res.setHeader('Access-Control-Allow-Origin', '*');
//     res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
// });
Enter fullscreen mode Exit fullscreen mode

I still don't understand what happened. Any pointers / explanation would be appreciated much.

Collapse
 
edwardfernando profile image
Edward Fernando • Edited

Oh, this is because i missed the next() function call.

app.use((req, res, next) => {
    res.setHeader('Access-Control-Allow-Origin', '*');
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
    next();
});
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
francescoxx profile image
Francesco Ciulla

oh I see! glad you fixed it