My current project involves developing the front end by mocking the back-end using the expressjs library.
Within my project, I have a file called data.json which stores objects like the following:
"singleExecutions":[
{"executionId":190, "label":"exe_190"},
{"executionId":191, "label":"exe_191"},
...]
The goal is to route requests of the type /executions/executionId to retrieve the specific object from the singleExecutions list based on the requested Id. To achieve this, after consulting the expressjs documentation, it seems that I need to do something along these lines:
const express = require('express');
const data = require('./data');
// 1. Create an express router.
const router = express.Router();
// 2. Handle the requests.
router.get('/executions/:executionId', (req, res) => {
res.json(data.singleExecutions);
});
// 3. Start the server.
mockBackend.start(router);
It's worth noting that certain variables used in the above code snippet, such as mockBackend, are defined elsewhere in the application and work correctly with other requests not shown here.
However, when I try to access the URL /executions/190 (for example), I encounter the following exception:
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'executions/190'
Error: Cannot match any routes. URL Segment: 'executions/190'
at ApplyRedirects.noMatchError (webpack-internal:///../../../router/esm5/router.js:1848)
...
It appears there may be a misconfiguration within my router.get() method, but I'm struggling to identify the issue. Can anyone provide assistance?
Additionally, within the same codebase, if I navigate to the GET request /executions, it is successfully routed as follows:
router.get('/executions', (req, res) => {
res.json(data.executions);
});
...with all other aspects remaining unchanged.