REST client is stopped when angular application running

笑着哭i 提交于 2019-12-11 17:32:25

问题


In my application, I'm using a REST client and an Angular application generated by composer-cli. In sometimes, the REST client is terminated while I'm using the Angular app.

I noticed that this termination happens especially whenever I'm trying to use images in the Angular app. It seems an unwanted request is sent to the REST client when the image is loading.

REST client's log is as below.

I'm using a default generated Angular app. Any suggestions?


回答1:


I figured out the issue in my code. It was in the auto-generated proxy configuration file (proxy.conf.js).

module.exports = [{
    context: ['/auth', '/api'],
    target,
    secure: true,
    changeOrigin: true
}, {
    context: '/',
    target,
    secure: true,
    changeOrigin: true,
    ws: true,
    bypass: function (req, res, proxyOptions) {
        const accept = req.headers.accept || '';
        if (accept.indexOf('html') !== -1) {
            return '/index.html';
        }
    }
}];

I changed above part to,

module.exports = [{
    context: ['/auth', '/api'],
    target,
    secure: true,
    changeOrigin: true
}];

and also images should be located in ./src/assets folder.



来源:https://stackoverflow.com/questions/52130688/rest-client-is-stopped-when-angular-application-running

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!