Angular应用程序运行时REST客户端停止 [英] REST client is stopped when angular application running

查看:70
本文介绍了Angular应用程序运行时REST客户端停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我使用的是REST客户端和composer-cli生成的Angular应用程序.有时,当我使用Angular应用程序时,REST客户端会终止.

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.

我注意到这种终止特别是在我尝试在Angular应用中使用图像时发生.加载映像时,似乎有不需要的请求发送到REST客户端.

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客户端的日志如下.

REST client's log is as below.

我正在使用默认生成的Angular应用.有什么建议吗?

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

推荐答案

我在代码中发现了问题.它在自动生成的代理配置文件(proxy.conf.js)中.

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';
        }
    }
}];

我将上面的部分更改为

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

,图像也应位于./src/assets文件夹中.

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

这篇关于Angular应用程序运行时REST客户端停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆