Cannot get /api call from the backend although my build was successfull

My build got successfully deployed but I am getting cannot /GET for my api
app.use(‘/api’,require(“./Routes/CreateUser”));
app.use(‘/api’,require(“./Routes/DisplayData”));
app.use(‘/api’,require(“./Routes/OrderData”));
Routes file is also present in my backend directory, it’s woking locally but not after deployment

Attaching my github repo:

i noticed that your code refers to the env variable PORT, did you add a value in your dashboard for PORT, it can be a number like 8081 for instance, but it does need to be set because you use process.env.PORT

It looks like they have the PORT in a .env committed at the root of /backend and set to 4000, but it would just fall back to the default of 10000 without being set in their Render dashboard as an environment variable.

However, if they’re not taking advantage of Render’s monorepo support, they’ll want to instead.

Additionally, they’ve committed their MongoDB Atlas credentials and should roll them.

1 Like

The shared repo provides the answer here.

https://github.com/akaur1399/FoodHub/blob/main/backend/index.js

has

app.use(express.json());
app.use('/api',require("./Routes/CreateUser"));...

but then the included CreateUser file shows the route is defined as a POST - so a GET won’t work.

https://github.com/akaur1399/FoodHub/blob/main/backend/Routes/CreateUser.js#L11

router.post("/createuser", [
    body('email').isEmail(),
    // password must be at least 5 chars long
    body('password', 'Incorrect Password').isLength({ min: 5 })]
    , async (req, res) => {

        const errors = validationRe

John B
Render Support, UTC :uk:

2 Likes

yes I have added the port in the dashboard under environment variables

I have changed my foodData as /get and after that I can able to access my all food data but I am running my frontend the page is still not able to load the food information. What changes I have to make to get the data visible in my page? all the frontend components are having my backend link attached.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.