Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Angular/JS Express应用程序在生产模式下的无限路由循环中,在开发模式下运行良好_Javascript_Node.js_Angularjs_Express - Fatal编程技术网

Javascript Angular/JS Express应用程序在生产模式下的无限路由循环中,在开发模式下运行良好

Javascript Angular/JS Express应用程序在生产模式下的无限路由循环中,在开发模式下运行良好,javascript,node.js,angularjs,express,Javascript,Node.js,Angularjs,Express,我有一个基于fullstack的webapp。它在开发模式grunt-serve中工作得很好,但在生产模式grunt-serve:dist中却陷入了一个似乎无限的路由循环中 我的服务器控制台输出以下内容: Express server running on http://localhost:9000 in production mode finished populating things finished populating users GET / 200 39ms - 1.41kb GET

我有一个基于fullstack的webapp。它在开发模式grunt-serve中工作得很好,但在生产模式grunt-serve:dist中却陷入了一个似乎无限的路由循环中

我的服务器控制台输出以下内容:

Express server running on http://localhost:9000 in production mode
finished populating things
finished populating users
GET / 200 39ms - 1.41kb
GET /views/ui-editor/editor.html 200 15ms - 1.41kb
这就是我的NodeJS路由代码的样子:

module.exports = function(app) {

    // Server API Routes
    app.get('/api/awesomeThings', api.awesomeThings);

    app.post('/api/users', users.create);
    app.put('/api/users', users.changePassword);
    app.get('/api/users/me', users.me);
    app.get('/api/users/:id', users.show);

    app.post('/api/session', session.login);
    app.del('/api/session', session.logout);

    // All other routes to use Angular routing in app/scripts/app.js
    // TODO: redo so won't list all subfolders like this: http://stackoverflow.com/questions/18553847/express-angular-routing-causing-infinite-loop-crash
    app.get('/partials/*', index.partials);
    app.get('/common/*', index.partials);
    app.get('/ui-editor/*', index.partials);
    app.get('/*', middleware.setUserCookie, index.index);

    app.get('/:session', function(req, res) {
        res.render('views/index.html', {
            title: 'My App'
        });
    });

};
…和我的AngularJS路由代码:

$routeProvider
    .when('/main', {
        templateUrl: 'partials/main',
        controller: 'MainCtrl'
    })
    .when('/login', {
        templateUrl: 'partials/login',
        controller: 'LoginCtrl'
    })
    .when('/signup', {
        templateUrl: 'partials/signup',
        controller: 'SignupCtrl'
    })
    .when('/settings', {
        templateUrl: 'partials/settings',
        controller: 'SettingsCtrl',
        authenticate: true
    })
    .when('/:session', {
        templateUrl: 'views/ui-editor/editor.html',
        controller: 'weldEditorController'
    })
    .otherwise({
        redirectTo: '/my-project'
    });
更新:由于我怀疑文件被错误地复制到/dist文件夹中,以下是/dist的内容:

|-/.git (files inside)
|-/lib
|---config
|-----config.js
|-----dummydata.js
|-----env
|-------all.js
|-------development.js
|-------production.js
|-------test.js
|-----express.js
|-----passport.js
|---controllers
|-----api.js
|-----index.js
|-----session.js
|-----users.js
|---middleware.js
|---models
|-----thing.js
|-----user.js
|---routes.js
|---socket.js
|-/package.json
|-/Procfile
|-/public
|---bower_components (files inside)
|---images (files inside)
|---scripts
|-----c9afc898.vendor.js
|-----e4b45689.scripts.js
|---styles
|-----a5896f90.main.css
|-/server.js
|-/views
|---404.html
|---index.html
|---partials
|-----login.html
|-----main.html
|-----navbar.html
|-----settings.html
|-----signup.html
|---ui-editor
|-----editor.html
|-----weldPropertiesPanel.html

当某些资产无法加载时,问题最有可能出现

因为当前配置中的express server没有发送404,而是发送回索引,如routes.js中的这一行,导致无限循环并使浏览器窗口崩溃:

app.get('/*', middleware.setUserCookie, index.index);
可能只是找不到字体或角度模板。 调试的最佳方法是将上面的行更改为

app.get('/', middleware.setUserCookie, index.index);
并在网络选项卡中查看哪些http请求失败。
然后确保您的grunt构建作业复制了所有必需的文件/文件夹。

当某些资产无法加载时,问题最有可能出现

因为当前配置中的express server没有发送404,而是发送回索引,如routes.js中的这一行,导致无限循环并使浏览器窗口崩溃:

app.get('/*', middleware.setUserCookie, index.index);
可能只是找不到字体或角度模板。 调试的最佳方法是将上面的行更改为

app.get('/', middleware.setUserCookie, index.index);
并在网络选项卡中查看哪些http请求失败。
然后确保您的grunt构建作业复制了所有必需的文件/文件夹。

浏览器控制台中有任何输出吗?@AndreyShustariov:在我杀死服务器之前,什么都没有-然后它会对客户端JS文件发出许多GET请求。请参阅附加的文件/目录树。您怎么会认为这是一个无限路由循环问题?是否呈现editor.html视图?@AndreyShustariov我猜,由于Chrome状态栏在“等待服务器”之间切换。。。然后等待缓存…,最终挂起。No editor.html不呈现。浏览器控制台中有任何输出吗?@AndreyShustariov:在我杀死服务器之前,什么都没有-然后它会对客户端JS文件发出大量GET请求。请参阅附加的文件/目录树。你怎么会认为这是一个无限路由循环问题?是否呈现editor.html视图?@AndreyShustariov我猜,由于Chrome状态栏在“等待服务器”之间切换。。。然后等待缓存…,最终挂起。不,editor.html不呈现。这是很久以前的事了,但我想这已经解决了它。谢谢这是很久以前的事了,但我想这已经解决了。谢谢