-
Notifications
You must be signed in to change notification settings - Fork 68
/
serving-react-app-django.recipe
45 lines (28 loc) · 1.12 KB
/
serving-react-app-django.recipe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
1) Proxy the requests from :3000 to :8000 Done
2) Install django-cors-headers Done
3) Add 'corsheaders' to INSTALLED_APPS Done
4) Add 'corsheaders.middleware.CorsMiddleware' before 'CommonMiddleware' Done
5) Add CORS_ORIGIN_ALLOW_ALL = True on base settings Done.
6) Make Django load the bundles as static files with 'str(ROOT_DIR.path('frontend', 'build', 'static'))' Done
7) Create a views.py file on 'nomadgram' folder. Done
6) Create ReactAppView that reads the file. Done
7) Add the ReactAppView as a URL Done
urls.py:
from nomadgram import views
url(r'^', views.ReactAppView.as_view()),
from django.views.generic import View
from django.http import HttpResponse
from django.conf import settings
import os
class ReactAppView(View):
def get(self, request):
try:
with open(os.path.join(str(settings.ROOT_DIR), 'frontend', 'build', 'index.html')) as file:
return HttpResponse(file.read())
except:
return HttpResponse(
"""
index.html not found ! build your React app !!
""",
status=501,
)