Can Anyone help me please?
I’m trying to build a youtube clone website, but I get this error:
GET http://localhost:3000/search 404 (Not Found)
Uncaught (in promise) Error: Request failed with status code 404
at createError (createError.js:16:1)
at settle (settle.js:17:1)
at XMLHttpRequest.onloadend (xhr.js:66:1)
App.js:
import React from "react";
import axios from "axios";
import { Grid } from "@material-ui/core";
import { SearchBar, VideoDetail } from "./components";
import youtube from "./api/youtube";
class App extends React.Component {
state = {
video: [],
selectedVideo: null,
};
handleSubmit = async (searchTerm) => {
const response = await axios.get(""http://localhost:3000/search", youtube, {
params: {
part: "snippet",
maxResults: 5,
q: searchTerm,
},
});
this.setState = {
videos: response.data.items,
selectedVideo: response.data.items[0],
};
};
render() {
const { selectedVideo } = this.state;
return (
<Grid justifyContent="center" container spacing={10}>
<Grid item xs={12}>
<Grid container spacing={10}>
<Grid item xs={12}>
<SearchBar onFormSubmit={this.handleSubmit} />
</Grid>
<Grid item xs={8}>
<VideoDetail video={selectedVideo} />
</Grid>
<Grid item xs={4}>
{/*VIDEO DETAILS */}
</Grid>
</Grid>
</Grid>
</Grid>
);
}
}
export default App;
searchBar.js:
import React from "react";
import { Paper, TextField } from "@material-ui/core";
class SearchBar extends React.Component {
state = {
searchTerm: "",
};
handleChange = (event) => {
this.setState({ searchTerm: event.target.value });
this.handleSubmit = (event) => {
const { searchTerm } = this.state;
const { onFormSubmit } = this.props;
onFormSubmit(searchTerm);
event.preventDefault();
};
};
render() {
return (
<Paper elevation={6} style={{ padding: "25px" }}>
<form onSubmit={this.handleSubmit}>
<TextField
fullWidth
label="Search..."
onChange={this.handleChange}
></TextField>
</form>
</Paper>
);
}
}
export default SearchBar;
youtube.js:
import axios from "axios";
const key = "MY_API_KEY";
export default axios.create({
baseURL: "https://googleapis.com/youtube/v3",
});
Can someone please tell me what is wrong here?