Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Direct api calls #491

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cms/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class TestPosts(APITestCase, PermissionTestMixin):
'''cms/post'''

URL_PREFIX = '/cms/post'
URL_PREFIX = '/api/cms/post'

fixtures = get_app_fixtures([
'base',
Expand Down Expand Up @@ -55,7 +55,7 @@ def test_get_response_format(self):
class TestMenuItems(APITestCase, PermissionTestMixin):
'''cms/menu-item'''

URL_PREFIX = '/cms/menu-item'
URL_PREFIX = '/api/cms/menu-item'

fixtures = get_app_fixtures([
'base',
Expand Down
10 changes: 5 additions & 5 deletions competition/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def semester_assert_format(self, semester):
class TestSeries(APITestCase, PermissionTestMixin):
'''competition/series'''

URL_PREFIX = '/competition/series'
URL_PREFIX = '/api/competition/series'

fixtures = get_app_fixtures([
'base',
Expand Down Expand Up @@ -146,7 +146,7 @@ def test_permission_create(self):
class TestSemester(APITestCase, PermissionTestMixin):
'''competition/semester'''

URL_PREFIX = '/competition/semester'
URL_PREFIX = '/api/competition/semester'

fixtures = get_app_fixtures([
'base',
Expand Down Expand Up @@ -208,7 +208,7 @@ def test_staff_only_points_permissions(self):
class TestAPISemester(APITestCase, PermissionTestMixin):
'''competition/semester - Create all'''

URL_PREFIX = '/competition/semester/'
URL_PREFIX = '/api/competition/semester/'
fixtures = PermissionTestMixin.get_basic_fixtures()

def setUp(self):
Expand Down Expand Up @@ -240,7 +240,7 @@ def test_create_semester(self):

class TestCompetition(APITestCase, PermissionTestMixin):
'''competition/competition'''
URL_PREFIX = '/competition/competition'
URL_PREFIX = '/api/competition/competition'

fixtures = PermissionTestMixin.get_basic_fixtures()

Expand Down Expand Up @@ -324,7 +324,7 @@ def test_permission_create(self):

class TestSolution(APITestCase, PermissionTestMixin):
'''competition/solution'''
URL_PREFIX = '/competition/solution'
URL_PREFIX = '/api/competition/solution'

fixtures = get_app_fixtures([
'base',
Expand Down
6 changes: 3 additions & 3 deletions personal/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def setUp(self):
County.objects.create(name="Prešovský kraj"),
County.objects.create(name="Bratislavský kraj")]

URL_PREFIX = '/personal/counties'
URL_PREFIX = '/api/personal/counties'

def test_can_browse_all_counties(self):
response = self.client.get(self.URL_PREFIX, {}, 'json')
Expand Down Expand Up @@ -91,7 +91,7 @@ def setUp(self):
name="Rožňava", county=county1),
District.objects.create(name="Sabinov", county=county2)]

URL_PREFIX = '/personal/districts'
URL_PREFIX = '/api/personal/districts'

def test_can_browse_all_districts(self):
response = self.client.get(self.URL_PREFIX, {}, 'json')
Expand Down Expand Up @@ -211,7 +211,7 @@ def setUp(self):
)
]

URL_PREFIX = '/personal/schools'
URL_PREFIX = '/api/personal/schools'

def test_can_browse_all_schools(self):
response = self.client.get(self.URL_PREFIX, {}, 'json')
Expand Down
9 changes: 6 additions & 3 deletions webstrom/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.common.BrokenLinkEmailsMiddleware',
'allauth.account.middleware.AccountMiddleware',
]

Expand Down Expand Up @@ -165,19 +166,21 @@
USE_TZ = True

DATETIME_FORMAT = 'd.m.Y H:i:s'

API_PREFIX = 'api/'

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

STATIC_URL = '/static/'

STATIC_URL = 'static/'

# Media files

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

MEDIA_URL = '/media/'
MEDIA_URL = 'media/'
PRIVATE_STORAGE_ROOT = os.path.join(BASE_DIR, 'protected_media/')
SENDFILE_ROOT = PRIVATE_STORAGE_ROOT
SENDFILE_BACKEND = "django_sendfile.backends.simple"
Expand Down
5 changes: 0 additions & 5 deletions webstrom/settings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@
DEBUG = False

ALLOWED_HOSTS = [
"localhost",
"test.strom.sk",
]

CSRF_TRUSTED_ORIGINS = [
"https://test.strom.sk",
]

USE_X_FORWARDED_HOST = True

SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
Expand Down
15 changes: 10 additions & 5 deletions webstrom/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@
from django.contrib import admin
from django.urls import include, path

urlpatterns = [
path('django-admin/', admin.site.urls),
api_urlpatterns = [
path('user/', include('user.urls')),
path('competition/', include('competition.urls')),
path('cms/', include('cms.urls')),
path('personal/', include('personal.urls')),
path('base/', include('base.urls')),
path('protected/', include('downloads.urls')),
# Dočasná cesta pre allauth bez rest frameworku
]

urlpatterns = [
path('accounts/', include('allauth.urls')),
path('django-admin/', admin.site.urls),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rozmyslam.. predpokladam, ze toto mame tiez v nginx ako routu. tak ci next rewrity/middleware nedrzat naozaj in sync s nginxom - napr. lokalne tym padom mozeme spravit localhost:3000/django-admin a smerovat to bude na BE (podla toho, ktory aktualne pouzivame). v podstate aby FE podporoval vsetky routy, ktore podporuje deployed stranka, aj lokalne.

posli tym padom prosim niekam vycet vsetkeho, co v nginx mame definovane

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aktuálne ten nginx config vyzerá takto

server {
    location /static/ {
        proxy_pass http://localhost:8921/;
    }

    location /media/ {
        alias /data/www/webstrom-test/media/;
    }

    location /django-admin/ {
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Proto https;

        proxy_pass http://localhost:8920/django-admin/;
    }

    location /api/ {
    	proxy_set_header X-Forwarded-Host $host;
	proxy_set_header X-Forwarded-Proto https;

	proxy_pass http://localhost:8920/api/;
    }

    location / {
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Proto https;

        proxy_pass http://localhost:8922/;
    }
}

Neviem či musím nutne držať tie rewrity 1:1 s nginxom, asi mi skôr príde lepšie ich obmedziť len na to čo je nutné aby ten frontend sa dal vyvíjať a zvyšok si proste vždy vieme otvoriť na backende. Ale nemám na to nejaký silný názor.

path(settings.API_PREFIX, include(api_urlpatterns)),
]

# Pri vývoji servuj media files priamo z djanga
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT)
urlpatterns += static(
settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT
)
Loading