错误:[HPM]无效的上下文。预期类似:“ / api”或[“ / api”,“ / ajax”]

时间:2019-02-14 07:06:40

标签: angular

当我在Angular 7项目中没有进行任何更改时,出现了以下错误。直到昨天它都没有给出这个错误。

Error: [HPM] Invalid context. Expecting something like: "/api" or ["/api", "/ajax"]
at Object.matchContext [as match] (E:\Java\GitWorkspace\FE-Router\node_modules\http-proxy-middleware\lib\context-matcher.js:40:9)
at shouldProxy (E:\Java\GitWorkspace\FE-Router\node_modules\http-proxy-middleware\lib\index.js:82:27)
at middleware (E:\Java\GitWorkspace\FE-Router\node_modules\http-proxy-middleware\lib\index.js:39:9)
at app.use (E:\Java\GitWorkspace\FE-Router\node_modules\webpack-dev-server\lib\Server.js:347:22)
at Layer.handle [as handle_request] (E:\Java\GitWorkspace\FE-Router\node_modules\express\lib\router\layer.js:95:5)
at trim_prefix (E:\Java\GitWorkspace\FE-Router\node_modules\express\lib\router\index.js:317:13)
at E:\Java\GitWorkspace\FE-Router\node_modules\express\lib\router\index.js:284:7
at Function.process_params (E:\Java\GitWorkspace\FE-Router\node_modules\express\lib\router\index.js:335:12)
at next (E:\Java\GitWorkspace\FE-Router\node_modules\express\lib\router\index.js:275:10)
at goNext (E:\Java\GitWorkspace\FE-Router\node_modules\webpack-dev-server\node_modules\webpack-dev-middleware\lib\middleware.js:16:16)
at processRequest (E:\Java\GitWorkspace\FE-Router\node_modules\webpack-dev-server\node_modules\webpack-dev-middleware\lib\middleware.js:64:26)
at ready (E:\Java\GitWorkspace\FE-Router\node_modules\webpack-dev-server\node_modules\webpack-dev-middleware\lib\util.js:52:12)
at handleRequest (E:\Java\GitWorkspace\FE-Router\node_modules\webpack-dev-server\node_modules\webpack-dev-middleware\lib\util.js:168:5)
at Promise (E:\Java\GitWorkspace\FE-Router\node_modules\webpack-dev-server\node_modules\webpack-dev-middleware\lib\middleware.js:39:7)
at new Promise (<anonymous>)
at middleware (E:\Java\GitWorkspace\FE-Router\node_modules\webpack-dev-server\node_modules\webpack-dev-middleware\lib\middleware.js:38:12)

这是我的proxy.config.json

{
"/*": {
    "target": "http://localhost:8088",
    "secure": false,
    "changeOrigin": true,
    "logLevel": "debug"
}

}

此错误消息背后的原因是什么。我该如何删除该错误。请帮忙。

2 个答案:

答案 0 :(得分:0)

#include <iostream> #include <algorithm> #include <map> int main() { std::map<char,int> x = { { 'a',1 },{ 'b',2 },{'c',0} }; std::map<char,int>::iterator best = std::max_element(x.begin(),x.end(),[] (const std::pair<char,int>& a, const std::pair<char,int>& b)->bool{ return a.second < b.second; } ); std::cout << best->first << " , " << best->second << "\n"; } 无效的语法。为了代理所有请求,我们可以使用/*

中所述的/或通配符**

View More Details Here

答案 1 :(得分:0)

在我的情况下,错误是由于在context中混合了“常规”路径和通配符路径引起的

无效

const PROXY_CONFIG = [
  {
    context: ['/api', '/upload/**'],
    target: 'http://localhost:3000',
    secure: false,
    logLevel: 'debug'
  }
];

有效
注意:/**

之后被删除了
/upload