Revert "Merge pull request #1832 from SkynetLabs/redirect-hns-endpoint-to-hns-subdomain"

This reverts commit 1b64969461, reversing
changes made to 7da5a24c6e.
This commit is contained in:
Karol Wypchlo 2022-03-10 09:55:09 +01:00
parent ed3fba1db4
commit 6e3f7d76d5
No known key found for this signature in database
GPG Key ID: B515DE9EEBE241E1
2 changed files with 12 additions and 19 deletions

View File

@ -3,8 +3,7 @@ include /etc/nginx/conf.d/include/proxy-pass-internal;
include /etc/nginx/conf.d/include/portal-access-check; include /etc/nginx/conf.d/include/portal-access-check;
# variable definititions - we need to define a variable to be able to access it in lua by ngx.var.something # variable definititions - we need to define a variable to be able to access it in lua by ngx.var.something
set $skylink ''; # placeholder for the base64 skylink set $skylink ''; # placeholder for the raw 46 bit skylink
set $skylink_base32 ''; # placeholder for the base32 skylink
# resolve handshake domain by requesting to /hnsres endpoint and assign correct values to $skylink and $rest # resolve handshake domain by requesting to /hnsres endpoint and assign correct values to $skylink and $rest
rewrite_by_lua_block { rewrite_by_lua_block {
@ -75,16 +74,10 @@ rewrite_by_lua_block {
if ngx.var.path == "/" and skylink_rest ~= nil and skylink_rest ~= "" and skylink_rest ~= "/" then if ngx.var.path == "/" and skylink_rest ~= nil and skylink_rest ~= "" and skylink_rest ~= "/" then
ngx.var.path = skylink_rest ngx.var.path = skylink_rest
end end
-- assign base32 skylink to be used in proxy_pass
ngx.var.skylink_base32 = require("skynet.skylink").base32(ngx.var.skylink)
} }
# host header has to be adjusted to properly match server name # we proxy to another nginx location rather than directly to siad because we do not want to deal with caching here
proxy_set_header Host $skylink_base32.$skynet_portal_domain; proxy_pass https://127.0.0.1/$skylink$path$is_args$args;
# pass the skylink request to subdomain skylink server
proxy_pass $scheme://$server_addr$path$is_args$args;
# in case siad returns location header, we need to replace the skylink with the domain name # in case siad returns location header, we need to replace the skylink with the domain name
header_filter_by_lua_block { header_filter_by_lua_block {

View File

@ -123,14 +123,15 @@ location /abuse/report {
location /hns { location /hns {
include /etc/nginx/conf.d/include/cors; include /etc/nginx/conf.d/include/cors;
rewrite_by_lua_block { # match the request_uri and extract the hns domain and anything that is passed in the uri after it
local hns_domain = string.match(ngx.var.uri, "/hns/([^/?]+)") # example: /hns/something/foo/bar matches:
local path = string.match(ngx.var.uri, "/hns/[^/?]+(.*)") # > hns_domain: something
local args = ngx.var.args and ngx.var.is_args .. ngx.var.args or "" # > path: /foo/bar/
local hns_subdomain_url = ngx.var.scheme .. "://" .. hns_domain .. ".hns." .. ngx.var.skynet_portal_domain .. path .. args set_by_lua_block $hns_domain { return string.match(ngx.var.uri, "/hns/([^/?]+)") }
set_by_lua_block $path { return string.match(ngx.var.uri, "/hns/[^/?]+(.*)") }
return ngx.redirect(hns_subdomain_url, ngx.HTTP_MOVED_PERMANENTLY) proxy_set_header Host $host;
} include /etc/nginx/conf.d/include/location-hns;
} }
location /hnsres { location /hnsres {
@ -340,8 +341,7 @@ location ~ "^/(([a-zA-Z0-9-_]{46}|[a-z0-9]{55})(/.*)?)$" {
rewrite_by_lua_block { rewrite_by_lua_block {
local skynet_skylink = require("skynet.skylink") local skynet_skylink = require("skynet.skylink")
local base32_skylink = skynet_skylink.base32(ngx.var.skylink) local base32_skylink = skynet_skylink.base32(ngx.var.skylink)
local args = ngx.var.args and ngx.var.is_args .. ngx.var.args or "" local base32_url = ngx.var.scheme .. "://" .. base32_skylink .. "." .. ngx.var.skynet_portal_domain .. ngx.var.path .. ngx.var.is_args .. ngx.var.args
local base32_url = ngx.var.scheme .. "://" .. base32_skylink .. "." .. ngx.var.skynet_portal_domain .. ngx.var.path .. args
return ngx.redirect(base32_url, ngx.HTTP_MOVED_PERMANENTLY) return ngx.redirect(base32_url, ngx.HTTP_MOVED_PERMANENTLY)
} }