mars / heroku-cra-node

⚛️ How to use create-react-app with a custom Node server on Heroku
MIT License
927 stars 226 forks source link

service worker #12

Closed Sydney-o9 closed 6 years ago

Sydney-o9 commented 6 years ago

This is a great concept - thank you for taking the time to put this open source.

Quick note, I just tested it fetching the fresh create-react-app repo - it is using service workers .

react-ui/src/index.js

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';

ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();

I had to unregister the service worker to see /api correctly in both Chrome and Firefox. Safari was ok because it doesn't support Service Workers yet.

Any ideas?

serviceworkers

mars commented 6 years ago

According to the last item in the create-react-app Offline First Considerations docs, fixing this config for this repo’s example /api relative API path will require ejecting.

Perhaps the best solution is to document this limitation clearly, linking to the docs for disabling/unregistering the ServiceWorker.

I personally do not use the technique demonstrated by this repo. I always run APIs as separate web apps with CORS configured. Sorry this issue slipped under my radar. Thanks for bringing it up here!

mars commented 6 years ago

I just ran through a fresh install from the newest create-react-app with ServiceWorker enabled (default setup) to test this issue. Here's what I observed:

While the second observation is not the expected behavior, I'm not convinced this is a real issue with this project. The whole purpose of this project is to demonstrate self-hosting an API in the same app. If you want to deploy an API for use by other apps/origins, then run it and the React UI as a separate Heroku apps instead of using this single-app architecture.