Search code examples
angularjsnode.jsexpresssingle-page-applicationkraken.js

Krakenjs How to route all requests except some api calls to index.html?


How do I route all requests to index.html except some api calls and maybe some pages. since kraken way of routing is based on controller's directory, so if i do

// /controller/index.js
app.get('*', function(){
    res.sendFile(__dirname + '/public/index.html');
}); 

kraken would route all my requests to index.html including the api calls in /controller/api directory. so how can i make kraken to route some requests like /api to the /controller/api/index.js and the rest to /public/templates/index.html?


Solution

  • I'd put it as middleware after the router (use priority to make sure it ends up in the right place)

    module.exports = function setupJustServeTheAppEverywhere() {
       return function (req, res, next) {
          res.sendFile(__dirname + '/public/index.html');
       }
    };
    

    And have the config load that.