├── backend └── backendapi │ ├── api │ ├── __init__.py │ ├── migrations │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-36.pyc │ │ │ └── 0001_initial.cpython-36.pyc │ │ └── 0001_initial.py │ ├── tests.py │ ├── apps.py │ ├── __pycache__ │ │ ├── urls.cpython-36.pyc │ │ ├── admin.cpython-36.pyc │ │ ├── models.cpython-36.pyc │ │ ├── views.cpython-36.pyc │ │ ├── __init__.cpython-36.pyc │ │ └── serializers.cpython-36.pyc │ ├── admin.py │ ├── models.py │ ├── urls.py │ ├── views.py │ └── serializers.py │ ├── backendapi │ ├── __init__.py │ ├── __pycache__ │ │ ├── urls.cpython-36.pyc │ │ ├── wsgi.cpython-36.pyc │ │ ├── __init__.cpython-36.pyc │ │ └── settings.cpython-36.pyc │ ├── urls.py │ ├── wsgi.py │ └── settings.py │ ├── db.sqlite3 │ └── manage.py ├── frontend └── frontendapp │ ├── public │ ├── favicon.ico │ ├── manifest.json │ └── index.html │ ├── src │ ├── index.css │ ├── App.js │ ├── index.js │ ├── App.css │ ├── components │ │ ├── books.js │ │ └── login.js │ └── serviceWorker.js │ ├── package.json │ └── README.md ├── README.md └── .gitignore /backend/backendapi/api/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /backend/backendapi/backendapi/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /backend/backendapi/api/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /backend/backendapi/api/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /backend/backendapi/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nogostradamus/react-django-YT/HEAD/backend/backendapi/db.sqlite3 -------------------------------------------------------------------------------- /backend/backendapi/api/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class ApiConfig(AppConfig): 5 | name = 'api' 6 | -------------------------------------------------------------------------------- /frontend/frontendapp/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nogostradamus/react-django-YT/HEAD/frontend/frontendapp/public/favicon.ico -------------------------------------------------------------------------------- /backend/backendapi/api/__pycache__/urls.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nogostradamus/react-django-YT/HEAD/backend/backendapi/api/__pycache__/urls.cpython-36.pyc -------------------------------------------------------------------------------- /backend/backendapi/api/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Book 3 | 4 | # Register your models here. 5 | 6 | admin.site.register(Book) 7 | -------------------------------------------------------------------------------- /backend/backendapi/api/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | class Book(models.Model): 4 | title = models.TextField(max_length=32, blank=False, null=False) 5 | -------------------------------------------------------------------------------- /backend/backendapi/api/__pycache__/admin.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nogostradamus/react-django-YT/HEAD/backend/backendapi/api/__pycache__/admin.cpython-36.pyc -------------------------------------------------------------------------------- /backend/backendapi/api/__pycache__/models.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nogostradamus/react-django-YT/HEAD/backend/backendapi/api/__pycache__/models.cpython-36.pyc -------------------------------------------------------------------------------- /backend/backendapi/api/__pycache__/views.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nogostradamus/react-django-YT/HEAD/backend/backendapi/api/__pycache__/views.cpython-36.pyc -------------------------------------------------------------------------------- /backend/backendapi/api/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nogostradamus/react-django-YT/HEAD/backend/backendapi/api/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /backend/backendapi/api/__pycache__/serializers.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nogostradamus/react-django-YT/HEAD/backend/backendapi/api/__pycache__/serializers.cpython-36.pyc -------------------------------------------------------------------------------- /backend/backendapi/backendapi/__pycache__/urls.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nogostradamus/react-django-YT/HEAD/backend/backendapi/backendapi/__pycache__/urls.cpython-36.pyc -------------------------------------------------------------------------------- /backend/backendapi/backendapi/__pycache__/wsgi.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nogostradamus/react-django-YT/HEAD/backend/backendapi/backendapi/__pycache__/wsgi.cpython-36.pyc -------------------------------------------------------------------------------- /backend/backendapi/backendapi/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nogostradamus/react-django-YT/HEAD/backend/backendapi/backendapi/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /backend/backendapi/backendapi/__pycache__/settings.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nogostradamus/react-django-YT/HEAD/backend/backendapi/backendapi/__pycache__/settings.cpython-36.pyc -------------------------------------------------------------------------------- /backend/backendapi/api/migrations/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nogostradamus/react-django-YT/HEAD/backend/backendapi/api/migrations/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /backend/backendapi/api/migrations/__pycache__/0001_initial.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nogostradamus/react-django-YT/HEAD/backend/backendapi/api/migrations/__pycache__/0001_initial.cpython-36.pyc -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | React with Django YouTube tutorial files 2 | https://www.youtube.com/watch?v=junWE5DoaVk 3 | 4 | 5 | Full course: https://www.udemy.com/react-django-full-stack/learn/lecture/14353606?couponCode=YT_MAX#overview Link includes a coupon code 6 | -------------------------------------------------------------------------------- /backend/backendapi/backendapi/urls.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from django.urls import path 3 | from django.conf.urls import include 4 | from rest_framework.authtoken.views import obtain_auth_token 5 | 6 | urlpatterns = [ 7 | path('admin/', admin.site.urls), 8 | path('api/', include('api.urls')), 9 | path('auth/', obtain_auth_token) 10 | ] 11 | -------------------------------------------------------------------------------- /frontend/frontendapp/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": ".", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /backend/backendapi/api/urls.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from django.urls import path 3 | from django.conf.urls import include 4 | from rest_framework import routers 5 | from .views import UserViewSet, BookViewSet 6 | 7 | router = routers.DefaultRouter() 8 | router.register('users', UserViewSet) 9 | router.register('books', BookViewSet) 10 | 11 | urlpatterns = [ 12 | path('', include(router.urls)), 13 | ] -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /frontend/frontendapp/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", 4 | "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /backend/backendapi/backendapi/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for backendapi project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backendapi.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /frontend/frontendapp/src/App.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import './App.css'; 3 | import Login from './components/login'; 4 | import Books from './components/books'; 5 | 6 | function App() { 7 | 8 | const [token, setToken] = useState(''); 9 | 10 | const userLogin = (tok) => { 11 | setToken(tok); 12 | } 13 | 14 | return ( 15 |
16 | 17 | 18 |
19 | ); 20 | } 21 | 22 | export default App; 23 | -------------------------------------------------------------------------------- /frontend/frontendapp/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import * as serviceWorker from './serviceWorker'; 6 | 7 | ReactDOM.render(, document.getElementById('root')); 8 | 9 | // If you want your app to work offline and load faster, you can change 10 | // unregister() to register() below. Note this comes with some pitfalls. 11 | // Learn more about service workers: https://bit.ly/CRA-PWA 12 | serviceWorker.unregister(); 13 | -------------------------------------------------------------------------------- /backend/backendapi/api/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 2.2.2 on 2019-06-26 22:37 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | initial = True 9 | 10 | dependencies = [ 11 | ] 12 | 13 | operations = [ 14 | migrations.CreateModel( 15 | name='Book', 16 | fields=[ 17 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 18 | ('title', models.TextField(max_length=32)), 19 | ], 20 | ), 21 | ] 22 | -------------------------------------------------------------------------------- /frontend/frontendapp/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | animation: App-logo-spin infinite 20s linear; 7 | height: 40vmin; 8 | pointer-events: none; 9 | } 10 | 11 | .App-header { 12 | background-color: #282c34; 13 | min-height: 100vh; 14 | display: flex; 15 | flex-direction: column; 16 | align-items: center; 17 | justify-content: center; 18 | font-size: calc(10px + 2vmin); 19 | color: white; 20 | } 21 | 22 | .App-link { 23 | color: #61dafb; 24 | } 25 | 26 | @keyframes App-logo-spin { 27 | from { 28 | transform: rotate(0deg); 29 | } 30 | to { 31 | transform: rotate(360deg); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /backend/backendapi/api/views.py: -------------------------------------------------------------------------------- 1 | from rest_framework import viewsets 2 | from rest_framework.authentication import TokenAuthentication 3 | from rest_framework.permissions import IsAuthenticated 4 | from django.contrib.auth.models import User 5 | from .serializers import UserSerializer, BookSerializer 6 | from .models import Book 7 | 8 | 9 | class UserViewSet(viewsets.ModelViewSet): 10 | queryset = User.objects.all() 11 | serializer_class = UserSerializer 12 | 13 | class BookViewSet(viewsets.ModelViewSet): 14 | queryset = Book.objects.all() 15 | serializer_class = BookSerializer 16 | authentication_classes = [TokenAuthentication, ] 17 | permission_classes = [IsAuthenticated, ] -------------------------------------------------------------------------------- /backend/backendapi/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backendapi.settings') 9 | try: 10 | from django.core.management import execute_from_command_line 11 | except ImportError as exc: 12 | raise ImportError( 13 | "Couldn't import Django. Are you sure it's installed and " 14 | "available on your PYTHONPATH environment variable? Did you " 15 | "forget to activate a virtual environment?" 16 | ) from exc 17 | execute_from_command_line(sys.argv) 18 | 19 | 20 | if __name__ == '__main__': 21 | main() 22 | -------------------------------------------------------------------------------- /backend/backendapi/api/serializers.py: -------------------------------------------------------------------------------- 1 | from rest_framework import serializers 2 | from django.contrib.auth.models import User 3 | from rest_framework.authtoken.models import Token 4 | from .models import Book 5 | 6 | class UserSerializer(serializers.ModelSerializer): 7 | class Meta: 8 | model = User 9 | fields = ['id', 'username', 'password'] 10 | extra_kwargs = {'password': {'write_only': True, 'required': True}} 11 | 12 | def create(self, validated_data): 13 | user = User.objects.create_user(**validated_data) 14 | Token.objects.create(user=user) 15 | return user 16 | 17 | class BookSerializer(serializers.ModelSerializer): 18 | class Meta: 19 | model = Book 20 | fields = ['id', 'title'] -------------------------------------------------------------------------------- /frontend/frontendapp/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frontendapp", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "react": "^16.8.6", 7 | "react-dom": "^16.8.6", 8 | "react-scripts": "3.0.1" 9 | }, 10 | "scripts": { 11 | "start": "react-scripts start", 12 | "build": "react-scripts build", 13 | "test": "react-scripts test", 14 | "eject": "react-scripts eject" 15 | }, 16 | "eslintConfig": { 17 | "extends": "react-app" 18 | }, 19 | "browserslist": { 20 | "production": [ 21 | ">0.2%", 22 | "not dead", 23 | "not op_mini all" 24 | ], 25 | "development": [ 26 | "last 1 chrome version", 27 | "last 1 firefox version", 28 | "last 1 safari version" 29 | ] 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /frontend/frontendapp/src/components/books.js: -------------------------------------------------------------------------------- 1 | import React, { Component} from 'react'; 2 | 3 | class Books extends Component { 4 | 5 | state = { 6 | books: [] 7 | } 8 | 9 | loadBooks = () => { 10 | fetch('http://127.0.0.1:8000/api/books/', { 11 | method: 'GET', 12 | headers: { 13 | 'Content-Type': 'application/json', 14 | Authorization: `Token ${this.props.token}` 15 | }, 16 | body: JSON.stringify(this.state.credentials) 17 | }) 18 | .then( data => data.json()) 19 | .then( 20 | data => { 21 | this.setState({books: data}) 22 | } 23 | ) 24 | .catch( error => console.error(error)) 25 | } 26 | 27 | render() { 28 | return ( 29 |
30 |

Books

31 | { this.state.books.map( book => { 32 | return

{book.title}

33 | })} 34 | 35 |
36 | ); 37 | } 38 | } 39 | 40 | export default Books; 41 | -------------------------------------------------------------------------------- /frontend/frontendapp/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 22 | React App 23 | 24 | 25 | 26 |
27 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /frontend/frontendapp/src/components/login.js: -------------------------------------------------------------------------------- 1 | import React, { Component} from 'react'; 2 | 3 | class Login extends Component { 4 | 5 | state = { 6 | credentials: {username: '', password: ''} 7 | } 8 | 9 | login = event => { 10 | fetch('http://127.0.0.1:8000/auth/', { 11 | method: 'POST', 12 | headers: {'Content-Type': 'application/json'}, 13 | body: JSON.stringify(this.state.credentials) 14 | }) 15 | .then( data => data.json()) 16 | .then( 17 | data => { 18 | this.props.userLogin(data.token); 19 | } 20 | ) 21 | .catch( error => console.error(error)) 22 | } 23 | 24 | register = event => { 25 | fetch('http://127.0.0.1:8000/api/users/', { 26 | method: 'POST', 27 | headers: {'Content-Type': 'application/json'}, 28 | body: JSON.stringify(this.state.credentials) 29 | }) 30 | .then( data => data.json()) 31 | .then( 32 | data => { 33 | console.log(data.token); 34 | } 35 | ) 36 | .catch( error => console.error(error)) 37 | } 38 | inputChanged = event => { 39 | const cred = this.state.credentials; 40 | cred[event.target.name] = event.target.value; 41 | this.setState({credentials: cred}); 42 | } 43 | 44 | render() { 45 | return ( 46 |
47 |

Login user form

48 | 49 | 55 |
56 | 62 |
63 | 64 | 65 |
66 | ); 67 | } 68 | } 69 | 70 | export default Login; 71 | -------------------------------------------------------------------------------- /frontend/frontendapp/README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 2 | 3 | ## Available Scripts 4 | 5 | In the project directory, you can run: 6 | 7 | ### `npm start` 8 | 9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 11 | 12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console. 14 | 15 | ### `npm test` 16 | 17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 19 | 20 | ### `npm run build` 21 | 22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance. 24 | 25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed! 27 | 28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 29 | 30 | ### `npm run eject` 31 | 32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 33 | 34 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 35 | 36 | Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 37 | 38 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 39 | 40 | ## Learn More 41 | 42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 43 | 44 | To learn React, check out the [React documentation](https://reactjs.org/). 45 | 46 | ### Code Splitting 47 | 48 | This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting 49 | 50 | ### Analyzing the Bundle Size 51 | 52 | This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size 53 | 54 | ### Making a Progressive Web App 55 | 56 | This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app 57 | 58 | ### Advanced Configuration 59 | 60 | This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration 61 | 62 | ### Deployment 63 | 64 | This section has moved here: https://facebook.github.io/create-react-app/docs/deployment 65 | 66 | ### `npm run build` fails to minify 67 | 68 | This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify 69 | -------------------------------------------------------------------------------- /backend/backendapi/backendapi/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for backendapi project. 3 | 4 | Generated by 'django-admin startproject' using Django 2.2.2. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.2/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/2.2/ref/settings/ 11 | """ 12 | 13 | import os 14 | 15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = '*!3w+z(@spo32^$1f)m0y82uabk^w6)%6%@-le)*#)5i2u3(kl' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | 'rest_framework', 41 | 'rest_framework.authtoken', 42 | 'corsheaders', 43 | 'api' 44 | ] 45 | 46 | MIDDLEWARE = [ 47 | 'django.middleware.security.SecurityMiddleware', 48 | 'django.contrib.sessions.middleware.SessionMiddleware', 49 | 'corsheaders.middleware.CorsMiddleware', 50 | 'django.middleware.common.CommonMiddleware', 51 | 'django.middleware.csrf.CsrfViewMiddleware', 52 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 53 | 'django.contrib.messages.middleware.MessageMiddleware', 54 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 55 | ] 56 | 57 | ROOT_URLCONF = 'backendapi.urls' 58 | 59 | TEMPLATES = [ 60 | { 61 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 62 | 'DIRS': [], 63 | 'APP_DIRS': True, 64 | 'OPTIONS': { 65 | 'context_processors': [ 66 | 'django.template.context_processors.debug', 67 | 'django.template.context_processors.request', 68 | 'django.contrib.auth.context_processors.auth', 69 | 'django.contrib.messages.context_processors.messages', 70 | ], 71 | }, 72 | }, 73 | ] 74 | 75 | WSGI_APPLICATION = 'backendapi.wsgi.application' 76 | 77 | CORS_ORIGIN_WHITELIST = [ 78 | "http://localhost:3000" 79 | ] 80 | 81 | 82 | # Database 83 | # https://docs.djangoproject.com/en/2.2/ref/settings/#databases 84 | 85 | DATABASES = { 86 | 'default': { 87 | 'ENGINE': 'django.db.backends.sqlite3', 88 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 89 | } 90 | } 91 | 92 | 93 | # Password validation 94 | # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators 95 | 96 | AUTH_PASSWORD_VALIDATORS = [ 97 | { 98 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 99 | }, 100 | { 101 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 102 | }, 103 | { 104 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 105 | }, 106 | { 107 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 108 | }, 109 | ] 110 | 111 | 112 | # Internationalization 113 | # https://docs.djangoproject.com/en/2.2/topics/i18n/ 114 | 115 | LANGUAGE_CODE = 'en-us' 116 | 117 | TIME_ZONE = 'UTC' 118 | 119 | USE_I18N = True 120 | 121 | USE_L10N = True 122 | 123 | USE_TZ = True 124 | 125 | 126 | # Static files (CSS, JavaScript, Images) 127 | # https://docs.djangoproject.com/en/2.2/howto/static-files/ 128 | 129 | STATIC_URL = '/static/' 130 | -------------------------------------------------------------------------------- /frontend/frontendapp/src/serviceWorker.js: -------------------------------------------------------------------------------- 1 | // This optional code is used to register a service worker. 2 | // register() is not called by default. 3 | 4 | // This lets the app load faster on subsequent visits in production, and gives 5 | // it offline capabilities. However, it also means that developers (and users) 6 | // will only see deployed updates on subsequent visits to a page, after all the 7 | // existing tabs open on the page have been closed, since previously cached 8 | // resources are updated in the background. 9 | 10 | // To learn more about the benefits of this model and instructions on how to 11 | // opt-in, read https://bit.ly/CRA-PWA 12 | 13 | const isLocalhost = Boolean( 14 | window.location.hostname === 'localhost' || 15 | // [::1] is the IPv6 localhost address. 16 | window.location.hostname === '[::1]' || 17 | // 127.0.0.1/8 is considered localhost for IPv4. 18 | window.location.hostname.match( 19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 20 | ) 21 | ); 22 | 23 | export function register(config) { 24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 25 | // The URL constructor is available in all browsers that support SW. 26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href); 27 | if (publicUrl.origin !== window.location.origin) { 28 | // Our service worker won't work if PUBLIC_URL is on a different origin 29 | // from what our page is served on. This might happen if a CDN is used to 30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 31 | return; 32 | } 33 | 34 | window.addEventListener('load', () => { 35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 36 | 37 | if (isLocalhost) { 38 | // This is running on localhost. Let's check if a service worker still exists or not. 39 | checkValidServiceWorker(swUrl, config); 40 | 41 | // Add some additional logging to localhost, pointing developers to the 42 | // service worker/PWA documentation. 43 | navigator.serviceWorker.ready.then(() => { 44 | console.log( 45 | 'This web app is being served cache-first by a service ' + 46 | 'worker. To learn more, visit https://bit.ly/CRA-PWA' 47 | ); 48 | }); 49 | } else { 50 | // Is not localhost. Just register service worker 51 | registerValidSW(swUrl, config); 52 | } 53 | }); 54 | } 55 | } 56 | 57 | function registerValidSW(swUrl, config) { 58 | navigator.serviceWorker 59 | .register(swUrl) 60 | .then(registration => { 61 | registration.onupdatefound = () => { 62 | const installingWorker = registration.installing; 63 | if (installingWorker == null) { 64 | return; 65 | } 66 | installingWorker.onstatechange = () => { 67 | if (installingWorker.state === 'installed') { 68 | if (navigator.serviceWorker.controller) { 69 | // At this point, the updated precached content has been fetched, 70 | // but the previous service worker will still serve the older 71 | // content until all client tabs are closed. 72 | console.log( 73 | 'New content is available and will be used when all ' + 74 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' 75 | ); 76 | 77 | // Execute callback 78 | if (config && config.onUpdate) { 79 | config.onUpdate(registration); 80 | } 81 | } else { 82 | // At this point, everything has been precached. 83 | // It's the perfect time to display a 84 | // "Content is cached for offline use." message. 85 | console.log('Content is cached for offline use.'); 86 | 87 | // Execute callback 88 | if (config && config.onSuccess) { 89 | config.onSuccess(registration); 90 | } 91 | } 92 | } 93 | }; 94 | }; 95 | }) 96 | .catch(error => { 97 | console.error('Error during service worker registration:', error); 98 | }); 99 | } 100 | 101 | function checkValidServiceWorker(swUrl, config) { 102 | // Check if the service worker can be found. If it can't reload the page. 103 | fetch(swUrl) 104 | .then(response => { 105 | // Ensure service worker exists, and that we really are getting a JS file. 106 | const contentType = response.headers.get('content-type'); 107 | if ( 108 | response.status === 404 || 109 | (contentType != null && contentType.indexOf('javascript') === -1) 110 | ) { 111 | // No service worker found. Probably a different app. Reload the page. 112 | navigator.serviceWorker.ready.then(registration => { 113 | registration.unregister().then(() => { 114 | window.location.reload(); 115 | }); 116 | }); 117 | } else { 118 | // Service worker found. Proceed as normal. 119 | registerValidSW(swUrl, config); 120 | } 121 | }) 122 | .catch(() => { 123 | console.log( 124 | 'No internet connection found. App is running in offline mode.' 125 | ); 126 | }); 127 | } 128 | 129 | export function unregister() { 130 | if ('serviceWorker' in navigator) { 131 | navigator.serviceWorker.ready.then(registration => { 132 | registration.unregister(); 133 | }); 134 | } 135 | } 136 | --------------------------------------------------------------------------------