Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-web
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Platform
Development
swh-web
Commits
2b85a438
Commit
2b85a438
authored
7 years ago
by
Antoine Lambert
Browse files
Options
Downloads
Patches
Plain Diff
swh-web: serve compressed assets in development mode
parent
499b1c8e
No related branches found
Branches containing commit
Tags
v0.0.124
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Makefile.local
+4
-4
4 additions, 4 deletions
Makefile.local
swh/web/settings/common.py
+7
-0
7 additions, 0 deletions
swh/web/settings/common.py
swh/web/settings/production.py
+5
-1
5 additions, 1 deletion
swh/web/settings/production.py
swh/web/urls.py
+8
-1
8 additions, 1 deletion
swh/web/urls.py
with
24 additions
and
6 deletions
Makefile.local
+
4
−
4
View file @
2b85a438
...
...
@@ -2,16 +2,16 @@ run-django-webpack-devserver:
bash
-c
"trap 'trap - SIGINT SIGTERM ERR; kill %1' SIGINT SIGTERM ERR; npm run start-dev & cd swh/web && python3 manage.py runserver"
run-django-webpack-dev
:
npm run build-dev
&&
cd
swh/web
&&
python3 manage.py runserver
npm run build-dev
&&
cd
swh/web
&&
python3 manage.py runserver
--nostatic
run-django-webpack-prod
:
npm run build
&&
cd
swh/web
&&
python3 manage.py runserver
--settings
=
swh.web.settings.production
npm run build
&&
cd
swh/web
&&
python3 manage.py runserver
--nostatic
--settings
=
swh.web.settings.production
run-django-server-dev
:
cd
swh/web
&&
python3 manage.py runserver
cd
swh/web
&&
python3 manage.py runserver
--nostatic
run-django-server-prod
:
cd
swh/web
&&
python3 manage.py runserver
--settings
=
swh.web.settings.production
cd
swh/web
&&
python3 manage.py runserver
--nostatic
--settings
=
swh.web.settings.production
run-gunicorn-server
:
gunicorn3
-b
127.0.0.1:5004 swh.web.wsgi
...
...
This diff is collapsed.
Click to expand it.
swh/web/settings/common.py
+
7
−
0
View file @
2b85a438
...
...
@@ -55,6 +55,13 @@ MIDDLEWARE = [
'
django.middleware.clickjacking.XFrameOptionsMiddleware
'
]
# Compress all assets (static ones and dynamically generated html)
# served by django in a local development environement context.
# In a production environment, assets compression will be directly
# handled by web servers like apache or nginx.
if
swh_web_config
[
'
debug
'
]:
MIDDLEWARE
.
insert
(
0
,
'
django.middleware.gzip.GZipMiddleware
'
)
ROOT_URLCONF
=
'
swh.web.urls
'
TEMPLATES
=
[
...
...
This diff is collapsed.
Click to expand it.
swh/web/settings/production.py
+
5
−
1
View file @
2b85a438
...
...
@@ -20,7 +20,11 @@ if os.environ['DJANGO_SETTINGS_MODULE'] == 'swh.web.settings.production':
from
.common
import
REST_FRAMEWORK
# activate per-site caching
MIDDLEWARE
.
insert
(
0
,
'
django.middleware.cache.UpdateCacheMiddleware
'
)
if
'
GZip
'
in
MIDDLEWARE
[
0
]:
MIDDLEWARE
.
insert
(
1
,
'
django.middleware.cache.UpdateCacheMiddleware
'
)
else
:
MIDDLEWARE
.
insert
(
0
,
'
django.middleware.cache.UpdateCacheMiddleware
'
)
MIDDLEWARE
+=
[
'
swh.web.common.middlewares.HtmlMinifyMiddleware
'
,
'
django.middleware.cache.FetchFromCacheMiddleware
'
]
...
...
This diff is collapsed.
Click to expand it.
swh/web/urls.py
+
8
−
1
View file @
2b85a438
...
...
@@ -3,10 +3,12 @@
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
from
django.conf
import
settings
from
django.conf.urls
import
(
url
,
include
,
handler400
,
handler403
,
handler404
,
handler500
)
from
django.contrib.staticfiles.urls
import
staticfiles_urlpatterns
from
django.contrib.staticfiles.views
import
serve
from
django.shortcuts
import
render
from
django.views.generic.base
import
RedirectView
...
...
@@ -32,7 +34,12 @@ urlpatterns = [
url
(
r
'
^jsreverse/$
'
,
urls_js
,
name
=
'
js_reverse
'
)
]
urlpatterns
+=
staticfiles_urlpatterns
()
# enable to serve compressed assets through django development server
if
settings
.
DEBUG
:
static_pattern
=
r
'
^%s(?P<path>.*)$
'
%
settings
.
STATIC_URL
[
1
:]
urlpatterns
.
append
(
url
(
static_pattern
,
serve
))
else
:
urlpatterns
+=
staticfiles_urlpatterns
()
handler400
=
swh_handle400
# noqa
handler403
=
swh_handle403
# noqa
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment