根据express.js中的设备提供不同的目录

时间:2019-01-17 10:45:02

标签: javascript node.js angular express

我已经构建了angular2 webApp的两个版本。  桌面版和移动版。 每个版本位于单独的目录中。 所以我试图根据请求应用程序的设备在express.js中提供不同的目录,但是我无法使其工作。...

<table class="table">
    <thead>
        <tr>
            <th scope="col">#</th>
            <th scope="col" ng-repeat="header in $ctrl.xlsxTableProps">{{header}}</th>                        
        </tr>
    </thead>
    <tr ng-repeat="item in $ctrl.parsedXslxData">
        <td>{{$index}}</td>
        <td ng-repeat="tableItem in $ctrl.xlsxTableProps"></td>
        <td>{{item[{{tableItem}}]}}</td>
    </tr>
</table>

当我尝试在移动模式或桌面模式下运行应用程序时,在浏览器中出现此错误:

app.use(express.static(path.join('../versions'),{index:false}))

app.use('/',(req,res,next)=>{
  const regEx = /mobile|iphone|ipod|android|blackberry|opera|mini|windows\sce|palm|smartphone|iemobile|ipad|android|android 3.0|xoom|sch-i800|playbook|tablet|kindle/i;
  let isMobile = regEx.test(req.headers['user-agent']);

  if(isMobile){
   return res.sendFile(path.join('/home/anton/dev/myTips/versions/mobileV/dist','/index.html'));
  }else{
    return res.sendFile(path.join('/home/anton/dev/myTips/versions/desktopV/dist/desktopV','/index.html'));
  }
})

0 个答案:

没有答案