Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Webapps Deliverer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vaclab
Webapps Deliverer
Commits
edf0c8e4
Commit
edf0c8e4
authored
4 years ago
by
Rolf Niepraschk
Browse files
Options
Downloads
Patches
Plain Diff
real hostname; compacting
parent
58b17b45
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
server.py
+27
-27
27 additions, 27 deletions
server.py
with
27 additions
and
27 deletions
server.py
+
27
−
27
View file @
edf0c8e4
from
flask
import
Flask
,
Response
,
request
,
send_from_directory
from
flask_cors
import
CORS
from
flask_cors
import
CORS
from
urllib.parse
import
urlparse
import
requests
,
json
import
re
app
=
Flask
(
__name__
)
COUCHDB_PROTO
=
'
http
'
COUCHDB_HOST
=
'
127.0.0.1
'
COUCHDB_PORT
=
'
5984
'
DB
=
'
vl_db
'
...
...
@@ -16,7 +15,6 @@ app.url_map.strict_slashes = False
CORS
(
app
)
## =================== URLs to the Web Apps ======================
@app.route
(
'
/<fn>
'
,
methods
=
[
'
GET
'
])
def
html
(
fn
):
app
.
logger
.
debug
(
'
hit html folder:
'
+
fn
)
...
...
@@ -41,17 +39,32 @@ def img(fn):
def
lib
(
fn
):
app
.
logger
.
debug
(
'
hit lib folder:
'
+
fn
)
return
send_from_directory
(
'
data/lib
'
,
fn
)
'''
The following works like a proxy server:
A flask server URL of the form
"
http://127.0.0.1:5000/5984/vl_db/000_SERVERS
"
will be forwarded to the real CouchDB URL
"
http://127.0.0.1:5984/vl_db/000_SERVERS
"
## ------------------------------------
## CouchDB Proxy
## from: http://host/5984/foo/bar
## to: http://127.0.0.1:5984/foo/bar
## ------------------------------------
# TODO: evtl besser make_response(...)?
def
couchdb_proxy_1
(
path
):
new_url
=
'
{}://{}:{}/{}
'
.
format
(
COUCHDB_PROTO
,
COUCHDB_HOST
,
\
COUCHDB_PORT
,
path
)
app
.
logger
.
debug
(
'
redirect to:
'
+
new_url
)
see:
https://stackoverflow.com/questions/6656363/proxying-to-another-web-service-with-flask
'''
@app.route
(
'
/{}/
'
.
format
(
COUCHDB_PORT
),
\
methods
=
[
'
GET
'
,
'
PUT
'
,
'
POST
'
,
'
HEAD
'
,
'
DELETE
'
,
'
OPTIONS
'
])
@app.route
(
'
/{}/<path:p>
'
.
format
(
COUCHDB_PORT
),
methods
=
[
'
GET
'
,
'
PUSH
'
,
'
POST
'
,
'
DELETE
'
])
def
couchdb_proxy
(
p
=
''
):
q
=
request
.
query_string
.
decode
();
if
q
:
path
=
p
+
'
?
'
+
q
else
:
path
=
p
host
=
urlparse
(
request
.
base_url
).
hostname
new_url
=
'
{}://{}:{}/{}
'
.
format
(
COUCHDB_PROTO
,
host
,
COUCHDB_PORT
,
path
)
app
.
logger
.
debug
(
'
[old couchdb url]
'
+
request
.
url
)
app
.
logger
.
debug
(
'
[new couchdb url]
'
+
new_url
)
resp
=
requests
.
request
(
method
=
request
.
method
,
url
=
new_url
,
...
...
@@ -65,19 +78,6 @@ def couchdb_proxy_1(path):
if
name
.
lower
()
not
in
excluded_headers
]
response
=
Response
(
resp
.
content
,
resp
.
status_code
,
headers
)
return
response
@app.route
(
'
/{}/
'
.
format
(
COUCHDB_PORT
),
\
methods
=
[
'
GET
'
,
'
PUT
'
,
'
POST
'
,
'
HEAD
'
,
'
DELETE
'
,
'
OPTIONS
'
])
@app.route
(
'
/{}/<path:path>
'
.
format
(
COUCHDB_PORT
),
methods
=
[
'
GET
'
,
'
PUSH
'
,
'
POST
'
,
'
DELETE
'
])
def
couchdb_proxy
(
path
=
''
):
app
.
logger
.
debug
(
'
original request:
'
+
request
.
url
)
q
=
request
.
query_string
.
decode
();
if
q
:
p
=
path
+
'
?
'
+
q
else
:
p
=
path
return
couchdb_proxy_1
(
p
);
if
__name__
==
'
__main__
'
:
app
.
run
(
host
=
'
0.0.0.0
'
,
port
=
8080
)
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