Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
douban-api-proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
douban-api-proxy
Commits
34e11fab
Commit
34e11fab
authored
Jul 14, 2016
by
janeczku
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support reverse proxy subdirectory
Closes #19
parent
d0c9bf9e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
0 deletions
+37
-0
web.py
cps/web.py
+37
-0
No files found.
cps/web.py
View file @
34e11fab
...
...
@@ -32,7 +32,44 @@ except ImportError, e:
use_generic_pdf_cover
=
True
from
shutil
import
copyfile
class
ReverseProxied
(
object
):
'''Wrap the application in this middleware and configure the
front-end server to add these headers, to let you quietly bind
this to a URL other than / and to an HTTP scheme that is
different than what is used locally.
Code courtesy of: http://flask.pocoo.org/snippets/35/
In nginx:
location /myprefix {
proxy_pass http://127.0.0.1:8083;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
proxy_set_header X-Script-Name /myprefix;
}
'''
def
__init__
(
self
,
app
):
self
.
app
=
app
def
__call__
(
self
,
environ
,
start_response
):
script_name
=
environ
.
get
(
'HTTP_X_SCRIPT_NAME'
,
''
)
if
script_name
:
environ
[
'SCRIPT_NAME'
]
=
script_name
path_info
=
environ
[
'PATH_INFO'
]
if
path_info
.
startswith
(
script_name
):
environ
[
'PATH_INFO'
]
=
path_info
[
len
(
script_name
):]
scheme
=
environ
.
get
(
'HTTP_X_SCHEME'
,
''
)
if
scheme
:
environ
[
'wsgi.url_scheme'
]
=
scheme
server
=
environ
.
get
(
'HTTP_X_FORWARDED_SERVER'
,
''
)
if
server
:
environ
[
'HTTP_HOST'
]
=
server
return
self
.
app
(
environ
,
start_response
)
app
=
(
Flask
(
__name__
))
app
.
wsgi_app
=
ReverseProxied
(
app
.
wsgi_app
)
formatter
=
logging
.
Formatter
(
"[
%(asctime)
s] {
%(pathname)
s:
%(lineno)
d}
%(levelname)
s -
%(message)
s"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment