{"id":19214323,"url":"https://github.com/fullstackreact/food-lookup-demo-rails","last_synced_at":"2025-05-12T22:20:59.389Z","repository":{"id":66101517,"uuid":"64874935","full_name":"fullstackreact/food-lookup-demo-rails","owner":"fullstackreact","description":"A demonstration of using `create-react-app` with a Rails API server","archived":false,"fork":false,"pushed_at":"2017-07-27T19:30:34.000Z","size":14926,"stargazers_count":93,"open_issues_count":2,"forks_count":56,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-20T19:36:59.596Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fullstackreact.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-08-03T19:53:30.000Z","updated_at":"2025-04-17T06:03:47.000Z","dependencies_parsed_at":"2023-03-03T14:30:24.620Z","dependency_job_id":null,"html_url":"https://github.com/fullstackreact/food-lookup-demo-rails","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fullstackreact%2Ffood-lookup-demo-rails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fullstackreact%2Ffood-lookup-demo-rails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fullstackreact%2Ffood-lookup-demo-rails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fullstackreact%2Ffood-lookup-demo-rails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fullstackreact","download_url":"https://codeload.github.com/fullstackreact/food-lookup-demo-rails/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253831215,"owners_count":21971051,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T14:09:36.468Z","updated_at":"2025-05-12T22:20:59.368Z","avatar_url":"https://github.com/fullstackreact.png","language":"JavaScript","funding_links":[],"categories":["Integrating with an API Backend"],"sub_categories":["Ruby on Rails"],"readme":"# `create-react-app` with a server example\n\n[![Dolphins](https://d17oy1vhnax1f7.cloudfront.net/items/3A1B470B1O2h0e0j1L47/dolphins.svg)](https://www.fullstackreact.com)\n\nThis project demonstrates using the setup generated by `create-react-app` alongside a Node Express API server.\n\n![](https://d17oy1vhnax1f7.cloudfront.net/items/042X2I1K1K0U2i1E460D/gifsicle-out.gif)\n\n### Detailed blog post\n\nWe have a [detailed blog post](https://www.fullstackreact.com/articles/how-to-get-create-react-app-to-work-with-your-rails-api/) that explains this repository.\n\n### Node+Express\n\nCheck out the [Node+Express](https://github.com/fullstackreact/food-lookup-demo) if that's your preferred API server platform.\n\n## Running\n\n```\ngit clone git@github.com:fullstackreact/food-lookup-demo-rails.git\ncd food-lookup-demo-rails\nbundle\ncd client\nnpm i\ncd ..\nrake start\n```\n\n## Overview\n\n`create-react-app` configures a Webpack development server to run on `localhost:3000`. This development server will bundle all static assets located under `client/src/`. All requests to `localhost:3000` will serve `client/index.html` which will include Webpack's `bundle.js`.\n\nTo prevent any issues with CORS, the user and her browser will communicate exclusively with the Webpack development server.\n\nInside `Client.js`, we use Fetch to make a request to the API:\n\n```js\n// Inside Client.js\nreturn fetch(`/api/food?q=${query}`, {\n  // ...\n})\n```\n\nThis request is made to `localhost:3000`, the Webpack dev server. Because the route has the special prefix `/api/`, the Webpack server knows that this request is actually intended for our API server. We specify in `package.json` that we would like Webpack to proxy API requests to `localhost:3001`:\n\n```js\n// Inside client/package.json\n\"proxy\": \"http://localhost:3001/\",\n```\n\nThis handy features is provided for us by `create-react-app`.\n\nTherefore, the user's browser makes a request to Webpack at `localhost:3000` which then proxies the request to our API server at `localhost:3001`:\n\n![](./flow-diagram.png)\n\nThis setup provides two advantages:\n\n1. If the user's browser tried to request `localhost:3001` directly, we'd run into issues with CORS.\n2. In many setups, this means that references to the API URL in development matches that in production. You don't have to do something like this:\n\n```js\n// Example API base URL determination in Client.js\nconst apiBaseUrl = process.env.NODE_ENV === 'development' ? 'localhost:3001' : '/'\n```\n\nThis setup uses [foreman](https://github.com/ddollar/foreman) for process management. Executing `foreman start` instructs Foreman to boot both the Webpack dev server and the API server.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffullstackreact%2Ffood-lookup-demo-rails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffullstackreact%2Ffood-lookup-demo-rails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffullstackreact%2Ffood-lookup-demo-rails/lists"}