WIP: API with 401
This commit is contained in:
@@ -5,6 +5,7 @@ import Modal from './components/Modal';
|
||||
import './App.scss';
|
||||
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
|
||||
import {faCaretDown, faCaretUp} from "@fortawesome/free-solid-svg-icons";
|
||||
import {postApi} from "./api/posts.api";
|
||||
|
||||
const App = () => {
|
||||
const [posts, setPosts] = useState([]);
|
||||
@@ -76,7 +77,8 @@ const App = () => {
|
||||
|
||||
return (
|
||||
<div className="app">
|
||||
<h1>Jodel Clone</h1>
|
||||
{console.log(postApi.getPostsByCoords(48, 9), process.env.REACT_APP_AUTH_USERNAME, process.env.REACT_APP_AUTH_PASSWORD)}
|
||||
<h1>SWA - Jodel</h1>
|
||||
<NewPostForm addPost={addPost} />
|
||||
<PostList
|
||||
posts={posts}
|
||||
|
||||
18
src/api/posts.api.js
Normal file
18
src/api/posts.api.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import axios from "axios"
|
||||
|
||||
const path = "https://api.jodel.anxietyprime.de/post";
|
||||
|
||||
const config = {
|
||||
headers: {
|
||||
auth: {
|
||||
username: process.env.REACT_APP_AUTH_USERNAME,
|
||||
password: process.env.REACT_APP_AUTH_PASSWORD,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const postApi = {
|
||||
async getPostsByCoords (lon, lat) {
|
||||
return (await axios.get(`${path}/${lon}/${lat}`, this.config)).data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user