Browse Source

More reliable method to retrieve endpoint webroot.

Stefano Cossu 7 years ago
parent
commit
8d3eb62700

+ 12 - 1
lakesuperior/endpoints/ldp.py

@@ -3,7 +3,7 @@ import logging
 from collections import defaultdict
 from collections import defaultdict
 from uuid import uuid4
 from uuid import uuid4
 
 
-from flask import Blueprint, request, send_file
+from flask import Blueprint, g, request, send_file, url_for
 from rdflib import Graph
 from rdflib import Graph
 from werkzeug.datastructures import FileStorage
 from werkzeug.datastructures import FileStorage
 
 
@@ -60,6 +60,17 @@ std_headers = {
     #'Allow' : ','.join(allow),
     #'Allow' : ','.join(allow),
 }
 }
 
 
+@ldp.url_defaults
+def bp_url_defaults(endpoint, values):
+    url_prefix = getattr(g, 'url_prefix', None)
+    if url_prefix is not None:
+        values.setdefault('url_prefix', url_prefix)
+
+@ldp.url_value_preprocessor
+def bp_url_value_preprocessor(endpoint, values):
+    g.url_prefix = values.pop('url_prefix')
+
+
 ## REST SERVICES ##
 ## REST SERVICES ##
 
 
 @ldp.route('/<path:uuid>', methods=['GET'])
 @ldp.route('/<path:uuid>', methods=['GET'])

+ 1 - 0
lakesuperior/store_layouts/rdf/simple_layout.py

@@ -196,3 +196,4 @@ class SimpleLayout(BaseRdfLayout):
         self.ds.remove((urn, RDF.type, nsc['fcsystem'].Tombstone))
         self.ds.remove((urn, RDF.type, nsc['fcsystem'].Tombstone))
         self.ds.remove((urn, nsc['fcrepo'].created, None))
         self.ds.remove((urn, nsc['fcrepo'].created, None))
         self.ds.remove((None, nsc['fcsystem'].tombstone, urn))
         self.ds.remove((None, nsc['fcsystem'].tombstone, urn))
+

+ 2 - 2
lakesuperior/util/translator.py

@@ -2,7 +2,7 @@ import logging
 
 
 from collections import defaultdict
 from collections import defaultdict
 
 
-from flask import request
+from flask import request, g
 from rdflib.term import URIRef
 from rdflib.term import URIRef
 
 
 from lakesuperior.dictionaries.namespaces import ns_collection as nsc
 from lakesuperior.dictionaries.namespaces import ns_collection as nsc
@@ -19,7 +19,7 @@ class Translator:
 
 
     @staticmethod
     @staticmethod
     def base_url():
     def base_url():
-        return request.host_url + request.path.split('/')[1]
+        return request.host_url + g.url_prefix
 
 
 
 
     @staticmethod
     @staticmethod

+ 6 - 2
server.py

@@ -18,9 +18,13 @@ logger.info('Starting LAKEsuperior HTTP server.')
 
 
 ## Configure enpoint blueprints here. ##
 ## Configure enpoint blueprints here. ##
 
 
-fcrepo.register_blueprint(ldp, url_prefix='/ldp')
+fcrepo.register_blueprint(ldp, url_prefix='/ldp', url_defaults={
+    'url_prefix': 'ldp'
+})
 # Legacy endpoint. @TODO Deprecate.
 # Legacy endpoint. @TODO Deprecate.
-fcrepo.register_blueprint(ldp, url_prefix='/rest')
+fcrepo.register_blueprint(ldp, url_prefix='/rest', url_defaults={
+    'url_prefix': 'rest'
+})
 fcrepo.register_blueprint(query, url_prefix='/query')
 fcrepo.register_blueprint(query, url_prefix='/query')
 
 
 # Initialize temporary folders.
 # Initialize temporary folders.