I can't expand the default routes

Hi guys,
I’ve been using Forest for about a year and I’m very satisfied with it.
I never needed complexe features, but now I do and I’m having a hard time expanding the default routes.

Expected behavior

Be able to expand the route for the put request of my models.

Actual behavior

The code in my route is never executed when I modify one of my Mission’s element in the Forest UI.

  router.put('/Mission/:id', (req, res, next) => {
    console.log(req.body);
    next();
  });

Context

  • forest-express-sequelize version: 6.1.2
  • express version: 4.16.3
  • sequelize version: 5.8.11

Thanks !

Hi @AlexandreDeMoura,

Could you give me more context about your issue (Network tabs of your browser, logs of your server if any, etc)? I guess if you route is not called, the corresponding call in the network tabs of your browser return a 404, right ?

My first guess would be that your URL should be fully writing with lower case (/mission/:recordId), but I might be more helpful with a little more informations :slight_smile:

You can find the documentation here for overriding a route if that can help.

Hi @jeffladiray and thank you for you time !
Well the api call is working perfectly fine

I just can’t access it on my code to expand his functionality.
What I don’t understand is that, if I put my code in app.js instead of /routes/Mission.js, then I can execute my code inside the router.

const express = require('express');
const requireAll = require('require-all');

const app = express();

app.put('/forest/Mission/:id', (req, res, next) => {
  console.log("test");
  next();
})

requireAll({
  dirname: __dirname + '/middlewares',
  recursive: true,
  resolve: Module => new Module(app),
});

module.exports = app;

In this situation, I can trigger the console.log() every time I update my Mission element in the UI.

I just tried to generate a new lumber project to check if I’m able to reproduce, but unfortunately, everything seems fine on my side using for eg. editing PUT route on my car model
in /routes/cars.js

// Update a Car
router.put('/cars/:recordId', permissionMiddlewareCreator.update(), (request, response, next) => {
  // Learn what this route does here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/routes/default-routes#update-a-record
  console.warn('here');
  next();
});

Did you edit anything in the app.js file ? In your sample, I can’t see the requireAll of the routes file, but I guess since everything work with the default code, this part should be fine.

Adding the route where you tried it will definitely work, since you added it before any other routes of the app.

Is there a possibility that another Mission/:id route is already declared elsewhere ?

I have generated a new project and indeed it’s working fine.
My project was pretty outdated so I think it was the problem.

Thanks again for your time !

Also, note that there is no permissions mw here - it is possible that for some reason this is not working also due to that and anyway - this is not a good example of how to override your routes :slight_smile:

3 Likes