-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'api/users' #18
Comments
Actually I never used lite-server. lite-server support was a contribution from @raduserbanescu. I just tried to test with lite-server and noticed that if I use index 1 for connect api mocker in middlewares, it just works but with 10, it doesn't work. But I don't know how that middleware definitions work in lite-server. Do you have any idea @raduserbanescu? |
When I use index 1 it almost works. I get a 'TypeError: Cannot read property 'type' of undefined' as mentioned in #13. Closed issue but without a solution? And thanks for that fast answer btw, appreciate it :) |
Do you have a custom response? If so, can you share the content of it? |
Hi there all! |
I think we need some tests with lite-server. We shouldn't break that implementations. For the custom responses, if lite-server doesn't use expressjs, that means |
Maybe we should also update our examples without using expressjs like: var url = require('url');
var fs = require('fs');
var path = require('path');
module.exports = function (request, response) {
var targetFileName = 'GET.json';
var typeQueryParam = url.parse(request.url, true).query.type;
// Check is a type parameter exist
if (typeQueryParam) {
// Generate a new targetfilename with that type parameter
targetFileName = 'GET_' + typeQueryParam + '.json';
// If file does not exist then respond with 404 header
if (!fs.accessSync(targetFileName)) {
response.statusCode = 404;
response.end();
return;
}
}
var filePath = path.join(__dirname, targetFileName);
var stat = fileSystem.statSync(filePath);
response.writeHead(200, {
'Content-Type': 'application/json',
'Content-Length': stat.size
});
var readStream = fs.createReadStream(filePath);
// We replaced all the event handlers with a simple call to readStream.pipe()
readStream.pipe(response);
} |
If it helps, I think tomorrow I can look into what changed in more recent versions that breaks custom responses. |
@koreem I forgot to change a variable. Final result should be: var url = require('url');
var fs = require('fs');
var path = require('path');
module.exports = function (request, response) {
var targetFileName = 'GET.json';
var typeQueryParam = url.parse(request.url, true).query.type;
// Check is a type parameter exist
if (typeQueryParam) {
// Generate a new targetfilename with that type parameter
targetFileName = 'GET_' + typeQueryParam + '.json';
// If file does not exist then respond with 404 header
if (!fs.accessSync(targetFileName)) {
response.statusCode = 404;
response.end();
return;
}
}
var filePath = path.join(__dirname, targetFileName);
var stat = fs.statSync(filePath);
response.writeHead(200, {
'Content-Type': 'application/json',
'Content-Length': stat.size
});
var readStream = fs.createReadStream(filePath);
// We replaced all the event handlers with a simple call to readStream.pipe()
readStream.pipe(response);
} For other example, all of the methods of request and response that we used( |
@muratcorlu Thanks, that example works. I still have to use id 1 for the middleware, but I don't think that's a problem. |
@koreem for lite-server specific implementation details, I need to check how is it working. Or maybe @raduserbanescu can help about that. Also I created a task for writing tests for lite-server impl(#19) and another task for updating examples to have expressjs dependency-free examples(#20). Don't hesitate for creating PRs for them :) |
I did a little research and this is what I found: 1. @muratcorlu The reason my custom responses no longer work in the newest version is because of a breaking change in 2. @koreem |
@raduserbanescu thanks for investigation the problem. Place for Please, can you create a separate issue that defines that body-parser problem? Then we can continue to discuss in that issue for this specific problem and I think we can stop discussion here. Is it ok also for you? @koreem |
@muratcorlu if (!fs.accessSync(targetFileName)) { See https://nodejs.org/api/fs.html#fs_fs_accesssync_path_mode where it says that var url = require('url');
var fs = require('fs');
var path = require('path');
module.exports = function (request, response) {
var targetFileName = 'GET.json';
var typeQueryParam = url.parse(request.url, true).query.type;
// Check is a type parameter exist
if (typeQueryParam) {
// Generate a new targetfilename with that type parameter
targetFileName = 'GET_' + typeQueryParam + '.json';
}
var filePath = path.join(__dirname, targetFileName);
// If file does not exist then respond with 404 header
try {
fs.accessSync(filePath);
}
catch (err) {
response.statusCode = 404;
response.end();
return;
}
var stat = fs.statSync(filePath);
response.writeHead(200, {
'Content-Type': 'application/json',
'Content-Length': stat.size
});
var readStream = fs.createReadStream(filePath);
// We replaced all the event handlers with a simple call to readStream.pipe()
readStream.pipe(response);
} |
@khelkun thanks for sharing. I think you are right. I was already planning to update examples without using expressjs helpers. So maybe you can trigger this by creating a pull-request for this example :) |
@muratcorlu: done #23 |
I get an error (see title) when using lite server. I used the same mocks for my webpack config and that one worked, but the lite server doesn't work. With webpack I run a production script to build everything in a dist folder. See setup below:
The text was updated successfully, but these errors were encountered: