Hello I am trying to extends the routes to add a smart action but they are just not picked up, the action is created but when I click on it it says that the route can not been reached
Expected behavior
The route to be created
Actual behavior
404 the route does not seems to be created
this is my code, located in a ./routes/labe.ts
import * as express from 'express';
import { PermissionMiddlewareCreator } from 'forest-express-sequelize';
import { label } from '../models';
const router = express.Router();
const permissionMiddlewareCreator = new PermissionMiddlewareCreator('label');
router.post('/actions/map-features', permissionMiddlewareCreator.smartAction(), (request, response) => {
console.log(request);
});
Can you try to call next() after your console.log ?
Hi @anon94532230 thanks for helping.
Calling next does not change anything.
more info:
- Changing the file (or any routes files) does not trigger a recompile by ts-node-dev (nodemon for typescript)
- even manyally triggering the recompilation does not add the route
I added a console.log of the Module inside the requireAll of routes and the new added route file is not there
requireAll({
dirname : path.join(__dirname, 'routes'),
recursive: true,
resolve : Module => {
console.log(Module);
app.use('/forest', Module);
},
});
I also notice (I am new to Admin Forest) that at the beginning those routes files where auto generated, but since then I have added new models but no corresponding route files and still I was able to make changes to those models calling there corresponding routes even if I didnt have a specific route file for them, is there a default set of routes generate per models or does this is working?
If i register the route manually everything works fine
app.use('/forest', require('./routes/label'));
Hi @Benjamin_Marquis, can you share with us your tsconfig.json
file?
Can you also:
- delete your
dist/
(generated) directory
- remove your call to
require
- launch the build with
npm build
And check that your new route has been correctly generated in the dist/
directory?
1 Like
Hello @GuillaumeGautreau thanks for your help.
It was not a problem with Admin Forest but ts-node-dev that I was using
i had the following dev command
"dev-tsc": "ts-node-dev --project ./tsconfig.json --ignore-watch node_modules --inspect=0.0.0.0:9339 -- ./server.ts"
I replaced with recommanded
"dev": "tsc && tsc --watch & nodemon --watch ./dist ./dist/server.js"
I followed the instruction as recommanded by @anon94532230 and it works fine !
2 Likes