【发布时间】:2019-09-25 03:59:02
【问题描述】:
我正在尝试使用 server.js 和 proxy.config.json 文件模拟服务,以便可以在量角器测试中使用该模拟服务。我的方法是拥有这样的测试文件:
const server = require('server');
const { get, post } = server.router;
const { json } = server.reply;
server({ port: 3000 }, [
get('/abc', ctx => {
return json({
foo: "bar"
})
})
]);
proxy.config.json 文件如下:
{
"/xyz": {
"target": "http://localhost:3000/abc",
"changeOrigin": true,
"secure": false,
"logLevel": "debug",
"pathRewrite": {
"^/xyz": ""
}
}
}
然后我通过调用来运行我的测试
ng e2e --proxy-config proxy.config.json
但是,我没有成功,因为我的应用程序在 http://localhost:49156 中运行,而我希望模拟的服务在 https://localhost:8443/xyz 中运行。如果我希望模拟和代理来自与应用程序相同的端口/协议(49156 和 HTTP)的东西,我可以这样做,但是,对于在端口 8443 和 https 中运行的服务,我不能这样做。有人可以帮我弄这个吗?我究竟做错了什么? 感谢您的宝贵时间。
【问题讨论】:
-
这是我发布问题时的演变stackoverflow.com/questions/55924287/…
标签: javascript angular typescript protractor angular-cli