简体   繁体   English

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

[英]Angular/JS Express app in infinite routing loop in production mode, works fine in development mode

I have a webapp built on generator-angular-fullstack . 我有一个基于generator-angular-fullstack It works fine in development mode ( grunt serve ), but gets stuck in what seems like an infinite routing loop when in production mode ( grunt serve:dist ). 它在开发模式( grunt serve )下工作良好,但是在生产模式( grunt serve:dist )下陷入了无限路由循环。

My server console outputs this: 我的服务器控制台输出以下内容:

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

This is what my NodeJS routing code looks like: 这是我的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'
        });
    });

};

...and my AngularJS routing code: ...以及我的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'
    });

UPDATE: Since I suspect that files are copied wrong into the /dist folder, here is the contents of /dist: 更新:由于我怀疑文件被错误地复制到/ 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

The problem most likely appears when some of the assets can't load. 当某些资产无法加载时,最有可能出现此问题。

Because instead of sending a 404 the express server in the current configuration just sends back index , as this line in routes.js , causing an infinite loop and crashing the browser window: 因为在当前配置中快递服务器没有发送404而是发送回index ,这是routes.js这一行, routes.js导致无限循环并导致浏览器窗口崩溃:

app.get('/*', middleware.setUserCookie, index.index);

It might be just a font or an angular template that is not found. 可能只是找不到字体或有角模板。 You best bet for debugging is to change the line above to 最好的调试方法是将上面的行更改为

app.get('/', middleware.setUserCookie, index.index);

and see which http requests fail in network tab. 并在“网络”标签中查看哪些HTTP请求失败。 then make sure your grunt build job copies over all the required files/folders. 然后确保你的grunt build了所有必需的文件/文件夹拷贝工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React.js 应用程序在开发模式下运行良好,但在构建(生产模式)后出现错误 - React.js app works fine in development mode but has errors after building (production mode) 在生产中出现此错误,但在开发中工作正常 - StripeInvalidRequestError: The `line_items` parameter is required in payment mode - Getting this error in production but works fine in development - StripeInvalidRequestError: The `line_items` parameter is required in payment mode React 应用程序无法通过其请求在生产中访问我的快速应用程序,但在开发中运行良好 - React app can't reach my express app in production with its requests but works fine in development 在webpack生产模式下发生错误,但在开发模式下运行良好 - An error happens in webpack production mode, but but works well at development mode Rails 4 App-JS在开发模式下可与Webrick一起使用,但不适用于Passenger / Apache2 - Rails 4 App - JS works with Webrick but not Passenger/Apache2 in Development Mode 启用html5mode的Angular和Express路由 - Angular and Express routing with html5mode enabled 如何在生产模式下使用React运行Express应用 - How to run Express app with React in production mode JavaScript开发和生产模式 - JavaScript development and production mode React Chat 应用程序在生产环境中运行良好,但在开发环境中无法正常运行(聊天应用程序)| React(使用 Materia-ui),Socket.io,Express - React Chat app works fine in Production but not in Development (Chat App) | React (with Materia-ui), Socket.io, Express Angular JS路由使无限循环 - Angular JS routing makes infinite loop
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM