gpt4 book ai didi

node.js - 是什么原因导致 localhost :4200 to be added in front of route call?

转载 作者:太空宇宙 更新时间:2023-11-03 23:54:32 25 4
gpt4 key购买 nike

我正在尝试调用 API,但由于某种原因 localhost:4200 被添加到对 localhost:3000 的路由调用前面。

我多次查看了我的代码,发现另一个 API 调用与我用来执行此 API 调用的相同类型的代码运行良好。

这是我的服务:

import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { environment } from '../../environments/environment';

interface Tweet {
name: string;
}

@Injectable({
providedIn: 'root'
})
export class TweetService {
private url = environment.tweetsAPI;

httpOptions = {
headers: new HttpHeaders({'Content-Type': 'application/json'})
};

constructor(private http: HttpClient) {}

getTweets() {
console.log(this.url);
return this.http.get(this.url);
}
}

这是我的路线:

app.route('/get-tweets').get((req, res) => {
T.get('search/tweets', { q: 'iowa state since:2018-07-11 #gameday -filter:media -filter:retweets', count: 10 }, function(err, data, response) {
let filteredTweets = [];
_.each(data, userObj => {
filteredTweets.push(userObj);
})
return res.status(200).json({
message: 'Successfully returned tweets',
tweets: filteredTweets
})
})
})

在我的environment.ts文件中:

tweetsAPI: 'http:/localhost:3000/get-tweets'

收到此错误:

ERROR HttpErrorResponse {headers: HttpHeaders, status: 404, statusText: "Not Found", url: "http://localhost:4200/localhost:3000/get-tweets", ok: false, …}

最佳答案

替换 tweetsAPI:'http://localhost:3000/get-tweets'和tweetsAPI: ' http://localhost:3000/get-tweets '

关于node.js - 是什么原因导致 localhost :4200 to be added in front of route call?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57871451/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com