Skip to content

Commit

Permalink
fixes: STATIC_URL is hardcoded in read-view & nginx.conf (docker)
Browse files Browse the repository at this point in the history
  • Loading branch information
s3h10r committed May 31, 2020
1 parent c679f33 commit 675d088
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 29 deletions.
3 changes: 3 additions & 0 deletions Dockerfile.nginx
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
FROM nginx:latest
COPY ./nginx.conf /etc/nginx/nginx.conf
COPY ./docker.env /
RUN /bin/bash -c 'source /docker.env && sed -i "s|location /static/|location $STATIC_URL|g" /etc/nginx/nginx.conf'
RUN rm /docker.env
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ services:
- db

db:
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
image: postgres:11
env_file:
- ./docker.env
Expand Down
1 change: 1 addition & 0 deletions docker.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
POSTGRES_DB=postgres
POSTGRES_USER=postgres
POSTGRES_PASSWORD=password
STATIC_URL=/static/
2 changes: 1 addition & 1 deletion nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ worker_processes 16;
client_max_body_size 1024m;

location /static/ {
root /usr/src/reminiscence;
alias /usr/src/reminiscence/static/;
aio threads;
}
location = /favicon.ico { access_log off; log_not_found off; }
Expand Down
49 changes: 25 additions & 24 deletions pages/custom_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,12 @@ def read_customized(cls, usr, url_id, mode='read', req=None):
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{title}</title>
<script type="text/javascript" src="/static/js/pdf.min.js"></script>
<script type="text/javascript" src="/static/js/pdf.worker.min.js"></script>
<link type="text/css" href="/static/css/text_layer_builder.css" rel="stylesheet">
<script type="text/javascript" src="/static/js/annotator.min.js"></script>
<script src="/static/js/jquery-3.3.1.min.js"></script>
<link rel="stylesheet" href="/static/css/bootstrap.min.css">
<script type="text/javascript" src="{static_url}js/pdf.min.js"></script>
<script type="text/javascript" src="{static_url}js/pdf.worker.min.js"></script>
<link type="text/css" href="{static_url}css/text_layer_builder.css" rel="stylesheet">
<script type="text/javascript" src="{static_url}js/annotator.min.js"></script>
<script src="{static_url}js/jquery-3.3.1.min.js"></script>
<link rel="stylesheet" href="{static_url}css/bootstrap.min.css">
</head>
<body>
<div class="sticky-top">
Expand Down Expand Up @@ -712,7 +712,7 @@ def read_customized(cls, usr, url_id, mode='read', req=None):
""".format(pdf_url=row_url, annot_script=cls.ANNOTATION_SCRIPT,
title=row.title, pdf_pos_y=pdf_pos_y, js_post=cls.JS_POST,
get_cookies=cls.GET_COOKIES, pdf_start=pdfstart,
pagination_value=pagination_value, root_url_loc=cls.ROOT_URL_LOCATION)
pagination_value=pagination_value, root_url_loc=cls.ROOT_URL_LOCATION, static_url=settings.STATIC_URL)
data = bytes(pdf_template, "utf-8")
elif media_path.endswith(".epub"):
media_dir, media_file_with_ext = os.path.split(media_path)
Expand All @@ -735,10 +735,10 @@ def read_customized(cls, usr, url_id, mode='read', req=None):
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="/static/js/epub.min.js"></script>
<script src="/static/js/jquery-3.3.1.min.js"></script>
<link rel="stylesheet" href="/static/css/bootstrap.min.css">
<link rel="stylesheet" href="/static/css/themes.css">
<script src="{static_url}js/epub.min.js"></script>
<script src="{static_url}js/jquery-3.3.1.min.js"></script>
<link rel="stylesheet" href="{static_url}css/bootstrap.min.css">
<link rel="stylesheet" href="{static_url}css/themes.css">
</head>
<body>
<div id="viewer" class="spreads"></div>
Expand Down Expand Up @@ -1002,7 +1002,8 @@ def read_customized(cls, usr, url_id, mode='read', req=None):
</body>
</html>""".format(
back_url=back_url, row_url=row_url, url_id=url_id,
epub_cfi=epub_cfi, root_url_loc=cls.ROOT_URL_LOCATION
epub_cfi=epub_cfi, root_url_loc=cls.ROOT_URL_LOCATION,
static_url=settings.STATIC_URL
)
data = bytes(html, "utf-8")
elif row.url:
Expand Down Expand Up @@ -1082,13 +1083,13 @@ def format_note(row, media_path):
<head>
<meta charset="utf-8">
<title>{title}</title>
<link rel="stylesheet" href="/static/css/bootstrap.min.css">
<link rel="stylesheet" href="/static/css/bootstrap.min.css.map">
<script src="/static/js/jquery-3.3.1.min.js"></script>
<script src="/static/js/popper.min.js"></script>
<script src="/static/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="/static/css/summernote-bs4.css">
<script src="/static/js/summernote-bs4.js"></script>
<link rel="stylesheet" href="{static_url}css/bootstrap.min.css">
<link rel="stylesheet" href="{static_url}css/bootstrap.min.css.map">
<script src="{static_url}js/jquery-3.3.1.min.js"></script>
<script src="{static_url}js/popper.min.js"></script>
<script src="{static_url}js/bootstrap.min.js"></script>
<link rel="stylesheet" href="{static_url}css/summernote-bs4.css">
<script src="{static_url}js/summernote-bs4.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="referrer" content="no-referrer">
</head>
Expand Down Expand Up @@ -1162,7 +1163,7 @@ def format_note(row, media_path):
</body>
</html>
""".format(title="Notes", content=content)
""".format(title="Notes", content=contenti, static_url=settings.STATIC_URL)
return template

@classmethod
Expand Down Expand Up @@ -1348,7 +1349,7 @@ def custom_template(cls, title, content, row):
<head>
<meta charset="utf-8">
<title>{title}</title>
<link rel="stylesheet" href="/static/css/bootstrap.min.css">
<link rel="stylesheet" href="{static_url}css/bootstrap.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="referrer" content="no-referrer">
</head>
Expand Down Expand Up @@ -1389,8 +1390,8 @@ def custom_template(cls, title, content, row):
</div>
</div>
</div>
<script src="/static/js/jquery-3.3.1.min.js"></script>
<script src="/static/js/annotator.min.js"></script>
<script src="{static_url}js/jquery-3.3.1.min.js"></script>
<script src="{static_url}js/annotator.min.js"></script>
<script>
{annot_script}
{js_post}
Expand Down Expand Up @@ -1421,7 +1422,7 @@ def custom_template(cls, title, content, row):
card_bg=card_bg, card_tab=card_tab,
annot_script=cls.ANNOTATION_SCRIPT,
js_post=cls.JS_POST, html_pos_y=html_pos_y,
pdf_annot=pdf_annot)
pdf_annot=pdf_annot, static_url=settings.STATIC_URL)
return template

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions reminiscence/dockersettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@

# Add root url location, keep it blank or add location ex: /bookmark

ROOT_URL_LOCATION = ''
ROOT_URL_LOCATION = os.environ.get('ROOT_URL_LOCATION','')

TEMPLATES = [
{
Expand Down Expand Up @@ -184,7 +184,7 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/

STATIC_URL = '/static/'
STATIC_URL = os.environ.get('STATIC_URL','/static/')

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

Expand Down

0 comments on commit 675d088

Please sign in to comment.