HenricF
HenricF

Reputation: 218

Loopback throws UrlNotFoundError out of the box

I've been following the instructions for how to set up a Node.js application using Loopback as described onToptal and Developing APIs with Node.js and LoopBack.io. Following these steps, I get a UrlNotFoundError when I try to access the REST API for the application.

Steps to reproduce:

  1. Installed the Strongloop command line: $ npm install -g strongloop
  2. Run the Loopback's application generator: $ slc loopback.
  3. Run the project: $ node . The terminal displays the following
    Web server listening at: http://0.0.0.0:3000 Browse your REST API at http://0.0.0.0:3000/explorer
  4. Browse the REST API.
  5. Try to POST to /Users with the provided model.

This results in the following response:

{
  "error": {
    "statusCode": 404,
    "name": "Error",
    "message": "Cannot POST /api/Users",
    "status": 404,
    "stack": "Error: Cannot POST /api/Users\n    at raiseUrlNotFoundError (/Repos/loopback-test/node_modules/loopback/server/middleware/url-not-found.js:20:17)\n    at Layer.handle [as handle_request] (/Repos/loopback-test/node_modules/loopback/node_modules/express/lib/router/layer.js:95:5)\n    at trim_prefix (/Repos/loopback-test/node_modules/loopback/node_modules/express/lib/router/index.js:312:13)\n    at /Repos/loopback-test/node_modules/loopback/node_modules/express/lib/router/index.js:280:7\n    at Function.process_params (/Repos/loopback-test/node_modules/loopback/node_modules/express/lib/router/index.js:330:12)\n    at next (/Repos/loopback-test/node_modules/loopback/node_modules/express/lib/router/index.js:271:10)\n    at /loopback-test/node_modules/loopback/node_modules/async/dist/async.js:486:20\n    at replenish (/Repos/loopback-test/node_modules/loopback/node_modules/async/dist/async.js:879:29)\n    at /loopback-test/node_modules/loopback/node_modules/async/dist/async.js:888:13\n    at eachLimit$1 (/Repos/loopback-test/node_modules/loopback/node_modules/async/dist/async.js:3136:26)\n    at Object.<anonymous> (/Repos/loopback-test/node_modules/loopback/node_modules/async/dist/async.js:920:20)\n    at restApiHandler (/Repos/loopback-test/node_modules/loopback/server/middleware/rest.js:63:11)\n    at Layer.handle [as handle_request] (/Repos/loopback-test/node_modules/loopback/node_modules/express/lib/router/layer.js:95:5)\n    at trim_prefix (/Repos/loopback-test/node_modules/loopback/node_modules/express/lib/router/index.js:312:13)\n    at /Repos/loopback-test/node_modules/loopback/node_modules/express/lib/router/index.js:280:7\n    at Function.process_params (/Repos/loopback-test/node_modules/loopback/node_modules/express/lib/router/index.js:330:12)"
  }
}

What I have tried:

I run Mac OS X, version 10.11.6. I have Node, npm and other necessary tools installed.

What am I missing, or what can I do to avoid getting the raiseUrlNotFoundError, and access the REST API for my project?

Upvotes: 2

Views: 2417

Answers (3)

Loay
Loay

Reputation: 226

That problem is fixed with loopback 3.x, so please give it a try now. If you are still having the same issue, follow these instructions:

To remove this warning, disable the context middleware added by the built-in REST handler. Set the remoting.context property in server/config.json to false;

    {
  "remoting": {
    "context": false,
    // etc.
  },
  // etc.
}

for more info: http://loopback.io/doc/en/lb2/Using-current-context.html

Upvotes: 1

itinance
itinance

Reputation: 12428

To make it run just install the api-explorer

npm install --save loopback-component-explorer --save

and register the route as follows:

in the directory-structure from root-folder there is a folder called "server". Create an empty file named "component-config.json" into the "server"-folder and place the following code inside:

{
  "loopback-component-explorer": {
    "mountPath": "/explorer"
  }
}

Now you should be able to open the explorer-page with the url http://0.0.0.0:3000/explorer.

Upvotes: 2

uri wald
uri wald

Reputation: 338

I know it's not a really good solution but it's something (using win 10 64 bit). I got exactly the same error while creating the app slc loopback and selecting Loopback version 3.X , when recreated the app and selecting Loopback version 2.X the api works fine , probably that's the different between your projects.

Upvotes: 3

Related Questions