Is it possible to deploy a ReactJS website with json-server on Netlify?
Asked Answered
O

3

7

I have an application built with ReactJS, but I'm using a fake API (json-server) to handle my data.

So, before I run 'npm start' to run the application I have to run 'json-server server.json -p 3333' to run the server and I can't make it run on Netlify.

Does anybody know if it is possible or not?

Thanks!

Oskar answered 22/6, 2020 at 3:32 Comment(1)
I found this article but uses Github pages insteadTyeshatyg
S
1

You can run json-server on heroku or glitch. By using that url (provided by heroku or glitch) to fetch json data instead of localhost, you can deploy your website on netlify while your json server would be running on heroku or glitch. You can perform CRUD operations on the website deployed on netlify.

Procedure to upload JSON data on Glitch:

Or skip these steps and use the given url repository to test

For more details, visit: https://github.com/ikramdeveloper/json-server-deploy

Saadi answered 16/4, 2022 at 0:44 Comment(1)
Live example: reactjs-easy-peasy-blog.netlify.app and json-data is here seemly-truthful-scribe.glitch.me/postsSaadi
R
1

I ran into this issue as well. I discovered that you cannot run a JSON server on Netlify.

You can use something called Netlify Functions as a workaround. I believe each function mimics a server request. Each has its own URL and when you call a function, the Netlify server returns a JSON response.

Here is a Netlify forum that discusses it. https://answers.netlify.com/t/json-server-doesnt-work-on-netlify/32351

Recitation answered 13/8, 2022 at 15:50 Comment(0)
C
0

You can run JSON server on Heroku, that way you wont need to run both React and JSON server, as JSON server will already be running on a separate server at Heroku.

Its also free to run JSON server on Heroku too; https://github.com/eecs130/json-server-heroku#create-your-database

Once you have deployed JSON server on Heroku, your path then will be your db.json Resource name (example below is 'blogs');

    {
  "blogs": [
    {
      "postTitle": "My First Blog",

So your db.json REST API path to post to from your running instance of react will be; https://xxxx.herokuapp.com/blogs

Cowans answered 24/4, 2021 at 17:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.