Skip to content

Commit

Permalink
nginx: update nginx config for v1 api redirects and static files
Browse files Browse the repository at this point in the history
  • Loading branch information
tp-m committed Nov 4, 2024
1 parent 06c2391 commit 323ed2e
Showing 1 changed file with 84 additions and 13 deletions.
97 changes: 84 additions & 13 deletions nginx/default
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
##

# This is the web server config for wrapdb.mesonbuild.com

upstream uwsgi {
server 127.0.0.1:8081;
}

server {
location /v2 {
rewrite ^.*/v2/releases.json https://raw.githubusercontent.com/mesonbuild/wrapdb/master/releases.json permanent;
Expand All @@ -19,7 +16,8 @@ server {
}

# Redirect legacy v1 patch URLs.
# FIXME: This breaks download of sqlite that has not been imported to v2 because it is replaced by sqlite3
# FIXME: This breaks download of sqlite that has not been imported to v2 because it is replaced by sqlite3 (xclaesse)
# NOTE: no longer needed, we now serve v1 patch URLs directly from a static files mirror (in /var/www/v1-static, see below) (Tim, Nov 2024)
#location ~ get_zip$ {
# rewrite ^.*/v1/projects/([^/]+)/([^/]+)/([^/]+)/get_zip https://github.com/mesonbuild/wrapdb/releases/download/$1_$2-$3/$1_$2-$3_patch.zip permanent;
#}
Expand All @@ -28,18 +26,91 @@ server {
return 301 https://mesonbuild.com/Wrapdb-projects.html;
}

# Serve v1 files from a static mirror (requires redirects because the
# structure of the mirror can't 1:1 map to the file path in the request URIs,
# as we have to disambiguate files and directories for the same path).
# (Tim, 3 Nov 2024)
location /v1/ {

location / {
try_files $uri @uwsgi;
}
# v1 project list redirect
location = /v1/projects {
return 301 https://wrapdb.mesonbuild.com/v1-static/-/projects;
}

# v1 project info redirect
location /v1/projects/ {
rewrite ^.*/v1/projects/([^/]+)$ https://wrapdb.mesonbuild.com/v1-static/projects/-/$1 permanent;
}

# v1 get_latest redirect to static mirror
location /v1/query/get_latest/ {
rewrite ^.*/v1/query/get_latest/([^/]+)$ https://wrapdb.mesonbuild.com/v1-static/query/get_latest/-/$1 permanent;
}

# v1 get_wrap redirect to static mirror
location ~ /v1/projects/[^/]+/[^/]+/[^/]+/get_wrap$ {
rewrite ^.*/v1/projects/([^/]+)/([^/]+)/([^/]+)/get_wrap$ https://wrapdb.mesonbuild.com/v1-static/projects/$1/$2/$3/-/get_wrap permanent;
#rewrite ^.*/v1/projects/([^/]+)/([^/]+)/([^/]+)/get_wrap$ https://wrapdb.mesonbuild.com/v1-static/projects/$1/$2/$3/$1-$2-$3.wrap permanent;
}

location /static {
root /home/legeana/wrapweb/wrapweb/;
# v1 get_zip redirect to static mirror
location ~ /v1/projects/[^/]+/[^/]+/[^/]+/get_zip$ {
rewrite ^.*/v1/projects/([^/]+)/([^/]+)/([^/]+)/get_zip$ https://wrapdb.mesonbuild.com/v1-static/projects/$1/$2/$3/-/get_zip permanent;
#rewrite ^.*/v1/projects/([^/]+)/([^/]+)/([^/]+)/get_zip$ https://wrapdb.mesonbuild.com/v1-static/projects/$1/$2/$3/$1-$2-$3-wrap.zip permanent;
}
}

location @uwsgi {
include uwsgi_params;
uwsgi_pass uwsgi;
# Make sure v1 files served from static mirror are decorated with the
# right Content-type and where applicable Content-disposition headers.
#
location /v1-static/ {
root /var/www/;

# v1 project list (json)
location = /v1-static/-/projects {
types { }
default_type application/json;
}

# v1 project info (json)
location /v1-static/projects/-/ {
types { }
default_type application/json;
}

# v1 project latest version (json)
location /v1-static/query/get_latest/ {
types { }
default_type application/json;
}

# v1 get_wrap (text)
location ~ /v1-static/projects/[^/]+/[^/]+/[^/]+/-/get_wrap$ {
types { }
default_type "text/plain; charset=utf-8";
}

# v1 wrap file full name alias (text) (bonus addition, not part of the original v1 api)
location ~ /v1-static/projects/[^/]+/[^/]+/[^/]+/[^/]+.wrap$ {
types { }
default_type "text/plain; charset=utf-8";
}

# v1 get_zip (zip)
location ~ /v1-static/projects/[^/]+/[^/]+/[^/]+/-/get_zip$ {
types { }
default_type application/zip;
if ( $request_filename ~ "^.*/projects/([^/]+)/([^/]+)/([^/]+)/-/get_zip$" ){
set $fname $1-$2-$3-wrap.zip;
add_header Content-Disposition 'attachment; filename=$fname';
}
}

# v1 zip file full name alias (zip) (bonus addition, not part of the original v1 api)
location ~ /v1-static/projects/[^/]+/[^/]+/[^/]+/[^/]+.zip$ {
types { }
default_type application/zip;
}
}

server_name wrapdb.mesonbuild.com;
Expand Down

0 comments on commit 323ed2e

Please sign in to comment.