Hi.
The Boos Machine project is driving me nuts.
In app.js I have:
const express = require('express');
const app = express();
const cors = require('cors')
const bodyParser = require('body-parser');
const morgan = require('morgan')
const apiRouter = require('./server/api');
/* Do not change the following line! It is required for testing and allowing
* the frontend application to interact as planned with the api server
*/
const PORT = process.env.PORT || 4001;
// middleware for handling CORS requests from index.html
app.use(cors())
// Logging
app.use(morgan('dev'));
// bodyParser
app.use(bodyParser.json());
// Mount your existing apiRouter at the '/api' path.
app.use("/api", apiRouter);
// This conditional is here for testing purposes:
if (!module.parent) {
// Add your code to start the server listening at PORT below:
app.listen(PORT, console.log("I'm all ears at port", PORT))
}
My api.js is as follow (I know I have to move the child routers to separate modules, will do so as soon as I resolve this issue):
const express = require('express');
const apiRouter = express.Router();
// you need to set mergeParams: true on the router,
// if you want to access params from the parent router
const meetingsRouter = express.Router({ mergeParams: true });
// you can nest routers by attaching them as middleware:
apiRouter.use("/meetings", meetingsRouter);
meetingsRouter.post("/", (req, res, next) => {
console.log("Here!")
res.send("hi")
})
module.exports = apiRouter;
So, as soon as I open index.html my frontend somehow starts sending requests tlikePOST /api/meetings 200 0.883 ms - 2
and keep doing this until I navigate away. As soon as I am back to the landing page, the same happens:
And my FE receives apparently keeps rendering an array of empty meetings which are being created infinitely:
(cannot attach a second media file apparently but this is what it looks like)
Why would all this be happening? is it a bug? I guess it cannot be this as many would have had the same experience and reported it.
I honestly cannot see what I could have done wrong… As I said, it is just driving me crazy!
Thanks in advance!