PLEASE help us help you by writing a good post!
GitHub Repo: GitHub - danblock97/lol-stat-tracker: A League of Legends Stat Tracker using the Riot Games API. Built using React and Netlify Serverless functions
I have deployed the above site, it seemed to have rendered the frontend perfectly fine however, I can’t seem to get the functions to deploy (which I believe are the API endpoints) If you look in the repo, you will see a ‘client folder’ which is where Netlify would run the build command.
You will then see ‘netlify/functions’ and in there, all of the api endpoints which then link into the server.js file which you can also see.
Am I deploying this incorrectly? If so, how would I deploy it because after it deploys I see the below message:
I have just tried changing all axios.get requests to use
https://main--ubiquitous-dasik-c68acd.netlify.app/ instead of http://localhost5000 but no luck… If I change it back and start my server using ‘node server.js’ it all works.
The better the post - the faster the answer.
@DanBlock97 When you say:
Do you mean that you have your
set to Base directory
If so, that may be your problem.
directory documentation for functions says:
The default directory is
So if you have your
Base directory set to
client, but your functions situated above that, then Netlify won’t be seeing those functions.
If you had your
Base direcetory as
client you would need to move
Or you could perhaps change the folder location with additional configuration as per the documentation.
@nathanmartin Thank you, what I have now done is moved netlify/functions to inside the client folder and looks like it’s picked up all 6.
Now the issue I’m getting is it doesn’t seem to be working with the express server in the server.js file.
I.e one of my functions urls is https://ubiquitous-dasik-c68acd.netlify.app/.netlify/functions/championMastery
I have updated this which you can see in the latest commit on my linked repo however, it’s not loading anything.
Request failed with status code 502
Have I missed a step in getting the app to talk to the server.js file?
No, Netlify just doesn’t provide the kind of runtime node.js type hosting necessary for you to host that file.
Last reviewed by Netlify Support on December 2022
How do I run a server/database at Netlify?
We often get questions about how to run a specific backend server or database at Netlify. Examples of these types of questions include:
How to I get my node HTTP listener to respond to requests?
How do I start Mongo/MySQL/<insert-some-database-here> running on the server?
How can I SSH into my website?
We are here today to answer these questions - and the answer is: you can’t!
What do you m…
You don’t need to host your own server on Netlify, all your static files are deployed to and served automatically from the CDN.
If you want to provide convenience routes for your Netlify functions you would do that with
rewrites & proxies.
For example this
const searchRouter = require("./client/netlify/functions/search");
const rankedRouter = require("./client/netlify/functions/ranked");
const historyRouter = require("./client/netlify/functions/history");
const matchRouter = require("./client/netlify/functions/match");
const leaderboardRouter = require("./client/netlify/functions/leaderboard");
const championMasteryRouter = require("./client/netlify/functions/championMastery");
Could be in a
_redirects as something like:
/search /.netlify/functions/search 200
/ranked /.netlify/functions/ranked 200
/history /.netlify/functions/history 200
/match /.netlify/functions/match 200
/leaderboard /.netlify/functions/leaderboard 200
/champion-master /.netlify/functions/championMastery 200
As functions automatically deploy to
@nathanmartin Thank you so much for your help! I have managed to change all into an
_redirects file, changes my functions to become event handlers and everything works! I’ve been trying to figure this out for weeks and learned so much!