Make it easy to run Spaceport locally

This commit is contained in:
Tanner Collin 2022-04-06 22:54:55 +00:00
parent 3aea713a1b
commit 3529dbb359
4 changed files with 31 additions and 10 deletions

View File

@ -50,11 +50,13 @@ if DEBUG:
if BINDALL_ENV: if BINDALL_ENV:
ALLOWED_HOSTS = ['*'] ALLOWED_HOSTS = ['*']
SESSION_COOKIE_SECURE = False
CSRF_COOKIE_SECURE = False
else:
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
SECURE_REFERRER_POLICY = 'same-origin' SECURE_REFERRER_POLICY = 'same-origin'
# Application definition # Application definition
@ -65,7 +67,6 @@ INSTALLED_APPS = [
'django.contrib.contenttypes', 'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites', 'django.contrib.sites',
'rest_framework', 'rest_framework',
'rest_framework.authtoken', 'rest_framework.authtoken',
@ -89,6 +90,15 @@ MIDDLEWARE = [
'simple_history.middleware.HistoryRequestMiddleware', 'simple_history.middleware.HistoryRequestMiddleware',
] ]
if BINDALL_ENV:
INSTALLED_APPS += [
'corsheaders',
]
MIDDLEWARE += [
'corsheaders.middleware.CorsMiddleware',
]
CORS_ORIGIN_ALLOW_ALL = True
ROOT_URLCONF = 'apiserver.urls' ROOT_URLCONF = 'apiserver.urls'
TEMPLATES = [ TEMPLATES = [
@ -177,7 +187,8 @@ USE_TZ = True
# https://docs.djangoproject.com/en/3.0/howto/static-files/ # https://docs.djangoproject.com/en/3.0/howto/static-files/
if DEBUG: if DEBUG:
STATIC_URL = '/static/' MEDIA_URL = 'static/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'data/static')
else: else:
STATIC_URL = 'https://static.{}/'.format(PRODUCTION_HOST) STATIC_URL = 'https://static.{}/'.format(PRODUCTION_HOST)
STATIC_ROOT = os.path.join(BASE_DIR, 'data/static') STATIC_ROOT = os.path.join(BASE_DIR, 'data/static')

View File

@ -1,4 +1,5 @@
from django.conf.urls import url from django.conf.urls import url
from django.conf.urls.static import static
from django.contrib import admin from django.contrib import admin
from django.urls import include, path from django.urls import include, path
from rest_framework import routers from rest_framework import routers
@ -48,9 +49,11 @@ if secrets.IPN_RANDOM:
if secrets.ADMIN_RANDOM: if secrets.ADMIN_RANDOM:
ADMIN_ROUTE = '{}/admin/'.format(secrets.ADMIN_RANDOM) ADMIN_ROUTE = '{}/admin/'.format(secrets.ADMIN_RANDOM)
urlpatterns.append(path(ADMIN_ROUTE, admin.site.urls)) else:
ADMIN_ROUTE = 'admin/'
urlpatterns.append(path(ADMIN_ROUTE, admin.site.urls))
if settings.DEBUG: if settings.DEBUG:
urlpatterns += [ urlpatterns += [
path('api-auth/', include('rest_framework.urls')), path('api-auth/', include('rest_framework.urls')),
] ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

View File

@ -10,6 +10,7 @@ commonmark==0.9.1
defusedxml==0.6.0 defusedxml==0.6.0
Django==3.1.14 Django==3.1.14
django-allauth==0.41.0 django-allauth==0.41.0
django-cors-headers==3.11.0
django-rest-auth==0.9.5 django-rest-auth==0.9.5
django-simple-history==2.8.0 django-simple-history==2.8.0
djangorestframework==3.11.2 djangorestframework==3.11.2

View File

@ -3,9 +3,15 @@ import { Table } from 'semantic-ui-react';
export const randomString = () => Math.random().toString(36).substr(2, 10); export const randomString = () => Math.random().toString(36).substr(2, 10);
export const siteUrl = window.location.protocol + '//' + window.location.hostname; export const siteUrl = window.location.toString();
export const apiUrl = window.location.protocol + '//api.' + window.location.hostname; export const apiUrl = window.location.port ?
export const staticUrl = window.location.protocol + '//static.' + window.location.hostname; 'http://' + window.location.hostname + ':8000'
:
window.location.protocol + '//api.' + window.location.hostname;
export const staticUrl = window.location.port ?
'http://' + window.location.hostname + ':8000/static'
:
window.location.protocol + '//static.' + window.location.hostname;
export const isAdmin = (user) => user.is_staff || user.member.is_director || user.member.is_staff; export const isAdmin = (user) => user.is_staff || user.member.is_director || user.member.is_staff;
export const isInstructor = (user) => isAdmin(user) || user.member.is_instructor; export const isInstructor = (user) => isAdmin(user) || user.member.is_instructor;