|
58 | 58 | # URL Mapping |
59 | 59 | urls = ( |
60 | 60 | "/", "Main", |
| 61 | + "/static/(.*)", "Static", |
61 | 62 | '/favicon.ico', 'Favicon', |
62 | 63 | "/sparql/index", "SparqlIndex", |
63 | 64 | "/sparql/meta", "SparqlMeta", |
@@ -168,6 +169,36 @@ def GET(self): |
168 | 169 | current_subdomain = web.ctx.host.split('.')[0].lower() |
169 | 170 | return render.header(sp_title="", current_subdomain=current_subdomain) |
170 | 171 |
|
| 172 | +class Static: |
| 173 | + def GET(self, name): |
| 174 | + """Serve static files""" |
| 175 | + static_dir = "static" # o c.get("static", "static") se hai la path in conf.json |
| 176 | + file_path = os.path.join(static_dir, name) |
| 177 | + |
| 178 | + if not os.path.exists(file_path): |
| 179 | + raise web.notfound() |
| 180 | + |
| 181 | + # Content types |
| 182 | + ext = os.path.splitext(name)[1] |
| 183 | + content_types = { |
| 184 | + '.css': 'text/css', |
| 185 | + '.js': 'application/javascript', |
| 186 | + '.png': 'image/png', |
| 187 | + '.jpg': 'image/jpeg', |
| 188 | + '.jpeg': 'image/jpeg', |
| 189 | + '.gif': 'image/gif', |
| 190 | + '.svg': 'image/svg+xml', |
| 191 | + '.ico': 'image/x-icon', |
| 192 | + '.woff': 'font/woff', |
| 193 | + '.woff2': 'font/woff2', |
| 194 | + '.ttf': 'font/ttf', |
| 195 | + } |
| 196 | + |
| 197 | + web.header('Content-Type', content_types.get(ext, 'application/octet-stream')) |
| 198 | + |
| 199 | + with open(file_path, 'rb') as f: |
| 200 | + return f.read() |
| 201 | + |
171 | 202 | class Sparql: |
172 | 203 | def __init__(self, sparql_endpoint, sparql_endpoint_title, yasqe_sparql_endpoint): |
173 | 204 | self.sparql_endpoint = sparql_endpoint |
|
0 commit comments