log.js 647 B

123456789101112131415161718192021222324252627282930
  1. export const getLog = async () => {
  2. try {
  3. const res = await fetch("http://localhost:5000/log");
  4. return await res.json();
  5. } catch (error) {
  6. console.log("error", error);
  7. return false;
  8. }
  9. };
  10. export const addLog = async (data) => {
  11. try {
  12. const myHeaders = new Headers();
  13. myHeaders.append("Content-Type", "application/json");
  14. const raw = JSON.stringify(data);
  15. const requestOptions = {
  16. method: "POST",
  17. body: raw,
  18. headers: myHeaders,
  19. };
  20. const updated = await fetch(`http://localhost:5000/log/add`, requestOptions);
  21. return await updated.json();
  22. } catch (error) {
  23. console.log("error", error);
  24. return false;
  25. }
  26. };