Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度+;Express:API在将代码部署到Google云(GCP)时返回HTML而不是JSON_Javascript_Node.js_Angular_Google App Engine_Google Cloud Platform - Fatal编程技术网

Javascript 角度+;Express:API在将代码部署到Google云(GCP)时返回HTML而不是JSON

Javascript 角度+;Express:API在将代码部署到Google云(GCP)时返回HTML而不是JSON,javascript,node.js,angular,google-app-engine,google-cloud-platform,Javascript,Node.js,Angular,Google App Engine,Google Cloud Platform,这是我的项目结构: - /dist (Created after ng build --prod) - index.html - <Other JS/CSS files> - /e2e - /node_modules - app.yaml - server.mjs - package.json 以下是如何在server.mjs中编写我的端点 app.get('/api/description/:ticker', (req, res) => { // a

这是我的项目结构:

- /dist (Created after ng build --prod)
    - index.html
    - <Other JS/CSS files>
- /e2e
- /node_modules
- app.yaml
- server.mjs
- package.json
以下是如何在server.mjs中编写我的端点

app.get('/api/description/:ticker', (req, res) => {
    // api call here
});

...
...
...

app.get('/', (req, res) => {
    res.sendFile(path.join(__dirname, 'dist/index.html'));
});
我的所有端点都以/api开头

这是前端的一个示例呼叫

getDescription(ticker) {
   return this.http.get('api/description/' + ticker);
}
一切都在本地运行。但当我将它部署到GCP时,我似乎无法让它正常工作。上述项目结构与上传至GCP的结构相同

问题:

任何API调用都会返回index.html cause解析错误,但返回值为200 OK

error:
error: SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse (<anonymous>) at XMLHttpRequest.o (https://tradingapp-294407.wl.r.appspot.com/main-es2015.fc0026b256e2c70aaeae.js:1:1075999) at l.invokeTask (https://tradingapp-294407.wl.r.appspot.com/polyfills-es2015.6022d6f28e0500e60d30.js:1:7242) at Object.onInvokeTask (https://tradingapp-294407.wl.r.appspot.com/main-es2015.fc0026b256e2c70aaeae.js:1:962460) at l.invokeTask (https://tradingapp-294407.wl.r.appspot.com/polyfills-es2015.6022d6f28e0500e60d30.js:1:7163) at i.runTask (https://tradingapp-294407.wl.r.appspot.com/polyfills-es2015.6022d6f28e0500e60d30.js:1:2651) at u.invokeTask [as invoke] (https://tradingapp-294407.wl.r.appspot.com/polyfills-es2015.6022d6f28e0500e60d30.js:1:8292) at p (https://tradingapp-294407.wl.r.appspot.com/polyfills-es2015.6022d6f28e0500e60d30.js:1:20575) at XMLHttpRequest.f (https://tradingapp-294407.wl.r.appspot.com/polyfills-es2015.6022d6f28e0500e60d30.js:1:20899)
text: "<!doctype html>↵<html lang="en">↵↵<head>↵  <meta charset="utf-8">↵  <title>Codebase</title>↵  <base href="/">↵  <meta name="viewport" content="width=device-width, initial-scale=1">↵  <link rel="icon" type="image/x-icon" href="favicon.ico">↵  <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700,900&display=swap" rel="stylesheet">↵  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">↵<link rel="stylesheet" href="styles.34652ea53ab2d653f3ba.css"></head>↵↵<body class="mat-typography">↵  <app-root></app-root>↵<script src="runtime-es2015.66c79b9d36e7169e27b0.js" type="module"></script><script src="runtime-es5.66c79b9d36e7169e27b0.js" nomodule defer></script><script src="polyfills-es5.6e1055b712d0b250b19e.js" nomodule defer></script><script src="polyfills-es2015.6022d6f28e0500e60d30.js" type="module"></script><script src="scripts.7d536d3103fdc12500b7.js" defer></script><script src="main-es2015.fc0026b256e2c70aaeae.js" type="module"></script><script src="main-es5.fc0026b256e2c70aaeae.js" nomodule defer></script></body>↵↵</html>"
__proto__: Object



headers: kp {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}



message: "Http failure during parsing for https://tradingapp-294407.wl.r.appspot.com/api/autocomplete/aapl"



name: "HttpErrorResponse"
ok: false



status: 200



statusText: "OK"



url: "https://tradingapp-294407.wl.r.appspot.com/api/autocomplete/aapl"
错误:
错误:SyntaxError:XMLHttpRequest.o的JSON.parse()位置0处JSON中的意外标记<(https://tradingapp-294407.wl.r.appspot.com/main-es2015.fc0026b256e2c70aaeae.js:1:1075999)在l.invokeTask(https://tradingapp-294407.wl.r.appspot.com/polyfills-es2015.6022d6f28e0500e60d30.js:1:7242)在Object.onInvokeTask(https://tradingapp-294407.wl.r.appspot.com/main-es2015.fc0026b256e2c70aaeae.js:1:962460)在l.invokeTask(https://tradingapp-294407.wl.r.appspot.com/polyfills-es2015.6022d6f28e0500e60d30.js:1:7163)在i.runTask(https://tradingapp-294407.wl.r.appspot.com/polyfills-es2015.6022d6f28e0500e60d30.js:1:2651)在u.invokeTask[作为调用](https://tradingapp-294407.wl.r.appspot.com/polyfills-es2015.6022d6f28e0500e60d30.js:1:8292)在p(https://tradingapp-294407.wl.r.appspot.com/polyfills-es2015.6022d6f28e0500e60d30.js:1:20575)在XMLHttpRequest.f(https://tradingapp-294407.wl.r.appspot.com/polyfills-es2015.6022d6f28e0500e60d30.js:1:20899)
文本:“↵↵↵↵  ↵  代码基↵  ↵  ↵  ↵  ↵  ↵↵↵↵  ↵↵↵"
__原型:对象
标题:kp{normalizedNames:Map(0),lazyUpdate:null,lazyInit:ƒ}
消息:“在解析的过程中Http失败。”https://tradingapp-294407.wl.r.appspot.com/api/autocomplete/aapl"
名称:“HttpErrorResponse”
好:错
现状:200
状态文本:“确定”
url:“https://tradingapp-294407.wl.r.appspot.com/api/autocomplete/aapl"
我觉得这个问题与app.yaml文件有关,但在多次尝试和错误后,我无法得到正确的结果

有人知道为什么会这样吗

谢谢

注意:所有东西都在本地工作。在GCP中,页面加载了当前CSS等所有东西。只有API不工作

error:
error: SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse (<anonymous>) at XMLHttpRequest.o (https://tradingapp-294407.wl.r.appspot.com/main-es2015.fc0026b256e2c70aaeae.js:1:1075999) at l.invokeTask (https://tradingapp-294407.wl.r.appspot.com/polyfills-es2015.6022d6f28e0500e60d30.js:1:7242) at Object.onInvokeTask (https://tradingapp-294407.wl.r.appspot.com/main-es2015.fc0026b256e2c70aaeae.js:1:962460) at l.invokeTask (https://tradingapp-294407.wl.r.appspot.com/polyfills-es2015.6022d6f28e0500e60d30.js:1:7163) at i.runTask (https://tradingapp-294407.wl.r.appspot.com/polyfills-es2015.6022d6f28e0500e60d30.js:1:2651) at u.invokeTask [as invoke] (https://tradingapp-294407.wl.r.appspot.com/polyfills-es2015.6022d6f28e0500e60d30.js:1:8292) at p (https://tradingapp-294407.wl.r.appspot.com/polyfills-es2015.6022d6f28e0500e60d30.js:1:20575) at XMLHttpRequest.f (https://tradingapp-294407.wl.r.appspot.com/polyfills-es2015.6022d6f28e0500e60d30.js:1:20899)
text: "<!doctype html>↵<html lang="en">↵↵<head>↵  <meta charset="utf-8">↵  <title>Codebase</title>↵  <base href="/">↵  <meta name="viewport" content="width=device-width, initial-scale=1">↵  <link rel="icon" type="image/x-icon" href="favicon.ico">↵  <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700,900&display=swap" rel="stylesheet">↵  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">↵<link rel="stylesheet" href="styles.34652ea53ab2d653f3ba.css"></head>↵↵<body class="mat-typography">↵  <app-root></app-root>↵<script src="runtime-es2015.66c79b9d36e7169e27b0.js" type="module"></script><script src="runtime-es5.66c79b9d36e7169e27b0.js" nomodule defer></script><script src="polyfills-es5.6e1055b712d0b250b19e.js" nomodule defer></script><script src="polyfills-es2015.6022d6f28e0500e60d30.js" type="module"></script><script src="scripts.7d536d3103fdc12500b7.js" defer></script><script src="main-es2015.fc0026b256e2c70aaeae.js" type="module"></script><script src="main-es5.fc0026b256e2c70aaeae.js" nomodule defer></script></body>↵↵</html>"
__proto__: Object



headers: kp {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}



message: "Http failure during parsing for https://tradingapp-294407.wl.r.appspot.com/api/autocomplete/aapl"



name: "HttpErrorResponse"
ok: false



status: 200



statusText: "OK"



url: "https://tradingapp-294407.wl.r.appspot.com/api/autocomplete/aapl"