API's in deployment
Unanswered
New Guinea Freshwater Crocodile posted this in #help-forum
New Guinea Freshwater CrocodileOP
I made a site and implemented some REST API stuff to fetch some basic soil moisture data for display on the site. It worked perfectly fine in the local host but once I pushed it to my production branch, the spots where the fetched data would normally appear is now blank. I went in to the Vercel dashboard and added the Supabase DB Url and Anon Key as environment variables as well as having them in my .env.local file but still no luck. Anyone know why this is happening?
35 Replies
Is your rest api build in the Next project ?
New Guinea Freshwater CrocodileOP
Yeah, pretty sure. Not too familiar with web dev so I followed the docs so I'm assuming I did
If yes you cannot call your own api inside the project you need to call your services
New Guinea Freshwater CrocodileOP
Wait, I just looked and I don't think that's what I have. My apologies, got a bit confused. I think Supabase DB uses Rest APIs which is what I'm calling...? not too sure
I mean
You have your own api in api folder right ?
And your api is doing some stuff
If you want to call the api which is on api folder you cannot from a same project you have to do the stuff without calling api
New Guinea Freshwater CrocodileOP
I'm just gonna put the snippet that handles all that in here. I don't know how to explain this
'use client';
import React, {useEffect, useState} from 'react';
import {createClientSupabase} from '/utils/server'
const MiniWindow = ({title, sensor_id}) => {
const [sensorData, setSensorData] = useState([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
useEffect(() => {
const fetchData = async () => {
const supabase = createClientSupabase();
const { data, error } = await supabase
.from('sensor_data')
.select('*')
.eq('id',sensor_id);
if (error) {
console.error("Error fetching data:", error.message); // Log the error message
setError(error.message);
} else {
console.log(data) // this statement
setSensorData(data);
}
setLoading(false);
};
fetchData();
}, [sensor_id])
return (
<div
className="bg-[#708075] box-content rounded-lg shadow-lg flex-auto flex-col p-6 m-6 min-w-72 min-h-96 max-h-144 content-start overflow-auto grow-0">
<h2 className="box-border flex flex-auto text-[#f2f1f1] text-2xl justify-center mb-4 font-amiri">{title}</h2>
<ul>
{sensorData.map((sensor) => (
<li key={sensor.id}>
<strong>Soil Moisture:</strong> {sensor.moisture}
</li>
)
)}
</ul>
</div>
);
};
export default MiniWindow;@ItetsuLaTable And your api is doing some stuff
New Guinea Freshwater CrocodileOP
My bad, I don't know enough about this stuff to just talk about it without the code yet
Can you add js type the your comment ?
‘´´´js
New Guinea Freshwater CrocodileOP
Thought I did, hold up
@ItetsuLaTable Can you add js type the your comment ?
New Guinea Freshwater CrocodileOP
Did that work?
New Guinea Freshwater CrocodileOP
That works too
Im on my phone thats why perhzpd
Perhaps
Well, I dont understand well your issue there. Have you an error while fetching or you just have no values ?
@ItetsuLaTable Well, I dont understand well your issue there. Have you an error while fetching or you just have no values ?
New Guinea Freshwater CrocodileOP
Here are both deployments, local and prod (local has the data and prod is blank)
I changed nothing between these deployments aside from adding in the environment variables in the Vercel project dashboard for all deployments
Its like you dont have supabaseUrl in prod
Have you redeploye after giving env variables ?
New Guinea Freshwater CrocodileOP
Yes, several times
Do I need to make a new file that isn't .local for my .env file?
Where are you getting your supabase url ?
New Guinea Freshwater CrocodileOP
Straight from the DB dashboard
New Guinea Freshwater CrocodileOP
so do I do .env.public?
Noo just .env
New Guinea Freshwater CrocodileOP
Okay, let me try that
Next know how to switch between .env and .env.local if you are in dev mode or in prod
@ItetsuLaTable Next know how to switch between .env and .env.local if you are in dev mode or in prod
New Guinea Freshwater CrocodileOP
Adding that file worked. Thank you so much!