GuillaumeS
GuillaumeS

Reputation: 427

Strongloop / Loopback Getting started missing root.js

I'm following the getting started documentation from Loopback, and I have an issue when I want to add static files Strongloop getting started Step 3: the file /server/boot/root.js doesn't exists, in addition /server/server.js does not have the 2 lines that were supposed to be there :

//   var path = require('path');
//   app.use(loopback.static(path.resolve(__dirname, '../client')));

Instead, the /server/middleware.json shows :

"routes": {
    "loopback#status": {
      "paths": "/"
    }
  },

Could someone please let me know how to perform this step ? Note : the git repository for Step 3 is good, but not the scaffolded project running slc loopback.

Upvotes: 2

Views: 2073

Answers (2)

dbainbridge
dbainbridge

Reputation: 1202

The /server/middleware.json file is where middleware is registered now. The following excerpt is resolving to a file in module's server/middleware directory (loopback-getting-started/node_modules/loopback/server/middleware).

"routes": {
    "loopback#status": {
      "paths": "/"
    }
  },

Change this to:

"routes": {
  },

Restart the Loopback server and visiting localhost:3000 results in an Express error 404, which would be expected since you no longer have a route defined for /.

You now need to specify in the middleware.json file how to serve static content. You do this in the "files" phase:

"files": {
  "loopback#static": {
    "params": "$!../client"
  }
}

You can now add the following to an index.html file in your /client directory as the original documentation states.

<head><title>LoopBack</title></head>
<body>
    <h1>LoopBack Rocks!</h1>
    <p>Hello World... </p>
</body>

Restarting the Loopback server and visiting localhost:3000 now serves the index.html page.

More details about how to specify middleware via the new way is located at http://docs.strongloop.com/display/public/LB/Defining+middleware#Definingmiddleware-Registeringmiddlewareinmiddleware.json

Also see https://github.com/strongloop/loopback-faq-middleware

Upvotes: 1

superkhau
superkhau

Reputation: 2781

The latest version of LoopBack removed the root.js file. You do not need it anymore, the docs need to be updated to reflect this.

Upvotes: 0

Related Questions