node.jsloopbackjsstronglooploopback

how to render html page in loopback


hello guys i m new to loopback, can anyone help me with this following things when we install loopback by default we have client folder when we can place all our front end file now place all html file there and render these html file from router for eg ;-

var router = server.loopback.Router();
router.get('/', function(req, res) {
res.render('index');
});
router.get('/login', function(req, res) {
res.render('login');
});

i want something like this i have index,login html file in client folder so how i can do that i does lots of google but haven't find any soultion like this


Solution

    1. Assuming you created your project via loopback's CLI, you should have a server/boot/root.js file.

      'use strict';
      
      module.exports = function(server) {
        // Install a `/` route that returns server status
        var router = server.loopback.Router();
        router.get('/', server.loopback.status());
        server.use(router);
      };
      

      Either remove or change the route to server.loopback.status() (e.g. router.get('/status', server.loopback.status()).

    2. In server/middleware.json, you should see a line near the bottom with "files": {},.

      Modify it to the following:

      "files": {
        "loopback#static": {
          "params": "$!../client"
        }
      },
      
    3. Place all your static files into the client directory.

    This is from loopback's documentation: Add a static web page. I'd recommend going through all the Getting started with LoopBack documentation if you are new.