Krakenjs如何将除一些api调用之外的所有请求路由到index.html?

时间:2015-04-16 16:56:06

标签: angularjs node.js express single-page-application kraken.js

除了一些api调用和某些页面之外,我如何将所有请求路由到index.html。因为kraken的路由方式是基于控制器的目录,所以如果我这样做

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

kraken会将我的所有请求路由到index.html,包括/ controller / api目录中的api调用。那么我如何让kraken将/ api等请求路由到/controller/api/index.js,其余请求路由到/public/templates/index.html?

1 个答案:

答案 0 :(得分:1)

我把它作为路由器之后的中间件(使用优先级以确保它最终在正确的位置)

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

并配置加载。