adding next.js app which calls the fastAPI AND displays date in the app.

This commit is contained in:
lucas.oskorep
2023-07-10 21:21:41 -04:00
parent aad7babb2c
commit d24a340c15
6 changed files with 46 additions and 29 deletions

View File

@@ -1,16 +1,17 @@
'use client'
import React, {useEffect, useState} from 'react';
import {fetchStationData} from "@/services/api/mta-server";
import {fetchStartDate} from "@/services/mta-api/mta-server";
import {MtaStartTime} from "@/services/mta-api/types";
const TitleBar = () => {
const [data, setData] = useState(null);
const [data, setData] = useState<MtaStartTime|null>(null);
useEffect(() => {
const fetchData = async () => {
try {
console.log("CALLING API")
const mtaData = await fetchStationData([""])
const mtaData = await fetchStartDate([""])
setData( mtaData)
} catch (error) {

View File

@@ -1,16 +1,16 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
// rewrites: async () => {
// return [
// {
// source: '/api/:path*',
// destination:
// process.env.NODE_ENV === 'development'
// ? 'http://127.0.0.1:8000/api/:path*'
// : '/api/',
// },
// ]
// },
rewrites: async () => {
return [
{
source: '/api/:path*',
destination:
process.env.NODE_ENV === 'development'
? 'http://127.0.0.1:8000/api/:path*'
: '/api/',
},
]
},
}
module.exports = nextConfig

View File

@@ -1,11 +0,0 @@
export type MtaData = {
mtaData: any;
};
export const fetchStationData = async (stations:[string]):Promise<MtaData> => {
const res = await fetch("")
const data = await res.json()
return {
mtaData: data
};
};

View File

@@ -0,0 +1,19 @@
import {MtaData, MtaStartTime} from "@/services/mta-api/types";
export const fetchStationData = async (stations: [string]): Promise<MtaData> => {
const res = await fetch("/api/mta_data", {method: "POST"})
const data = await res.json()
return {
mtaData: data
};
};
export const fetchStartDate = async (stations: [string]): Promise<MtaStartTime> => {
const res = await fetch("/api/start_time", {method: "POST"})
const data = await res.text()
const date = new Date(data.replaceAll("\"", ""))
return {
startTime: date
};
};

View File

@@ -0,0 +1,7 @@
export interface MtaData {
mtaData: any;
};
export interface MtaStartTime {
startTime: Date
}