Merge remote-tracking branch 'origin/master' into docker

This commit is contained in:
Karol Wypchlo 2020-08-18 10:55:09 +02:00
commit 8a21dc8ce1
6 changed files with 42 additions and 10 deletions

1
.gitignore vendored
View File

@ -78,3 +78,4 @@ docker/data
# Cache files # Cache files
__pycache__ __pycache__
/.idea/ /.idea/
/venv/

View File

@ -79,7 +79,6 @@ services:
- 80 - 80
depends_on: depends_on:
- sia - sia
- health-check
- handshake-api - handshake-api
webapp: webapp:
@ -119,6 +118,7 @@ services:
container_name: handshake-api container_name: handshake-api
restart: unless-stopped restart: unless-stopped
environment: environment:
- HOSTNAME=0.0.0.0
- HSD_HOST=handshake - HSD_HOST=handshake
- HSD_NETWORK=main - HSD_NETWORK=main
- HSD_PORT=12037 - HSD_PORT=12037
@ -142,6 +142,11 @@ services:
networks: networks:
- shared - shared
environment: environment:
- HOSTNAME=0.0.0.0
- PORTAL_URL=nginx - PORTAL_URL=nginx
expose: expose:
- 3100 - 3100
depends_on:
- caddy
- handshake
- handshake-api

View File

@ -115,6 +115,7 @@ server {
location /hns { location /hns {
include /etc/nginx/conf.d/include/cors; include /etc/nginx/conf.d/include/cors;
include /etc/nginx/conf.d/include/proxy-buffer;
# if you are expecting large headers (ie. Skynet-Skyfile-Metadata), tune these values to your needs # if you are expecting large headers (ie. Skynet-Skyfile-Metadata), tune these values to your needs
proxy_buffer_size 128k; proxy_buffer_size 128k;
@ -179,6 +180,7 @@ server {
location ~ "^/([a-zA-Z0-9-_]{46}(/.*)?)$" { location ~ "^/([a-zA-Z0-9-_]{46}(/.*)?)$" {
include /etc/nginx/conf.d/include/cors; include /etc/nginx/conf.d/include/cors;
include /etc/nginx/conf.d/include/proxy-buffer;
limit_conn downloads_by_ip 100; # ddos protection: max 100 downloads at a time limit_conn downloads_by_ip 100; # ddos protection: max 100 downloads at a time
add_header Cache-Control "public, max-age=86400"; # allow consumer to cache response add_header Cache-Control "public, max-age=86400"; # allow consumer to cache response
@ -208,6 +210,7 @@ server {
location ~ "^/file/([a-zA-Z0-9-_]{46}(/.*)?)$" { location ~ "^/file/([a-zA-Z0-9-_]{46}(/.*)?)$" {
include /etc/nginx/conf.d/include/cors; include /etc/nginx/conf.d/include/cors;
include /etc/nginx/conf.d/include/proxy-buffer;
limit_conn downloads_by_ip 100; # ddos protection: max 100 downloads at a time limit_conn downloads_by_ip 100; # ddos protection: max 100 downloads at a time
add_header Cache-Control "public, max-age=86400"; # allow consumer to cache response add_header Cache-Control "public, max-age=86400"; # allow consumer to cache response

View File

@ -0,0 +1,4 @@
# if you are expecting large headers (ie. Skynet-Skyfile-Metadata), tune these values to your needs
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;

View File

@ -19,7 +19,8 @@ const clientOptions = {
}; };
const client = new NodeClient(clientOptions); const client = new NodeClient(clientOptions);
const startsWithSkylinkRegExp = /^[a-zA-Z0-9_-]{46}/; // Match both `sia://HASH` and `HASH` links.
const startsWithSkylinkRegExp = /^(sia:\/\/)?[a-zA-Z0-9_-]{46}/;
const getDomainRecords = async (name) => { const getDomainRecords = async (name) => {
const response = await client.execute("getnameresource", [name]); const response = await client.execute("getnameresource", [name]);
@ -31,7 +32,13 @@ const getDomainRecords = async (name) => {
}; };
const findSkylinkRecord = (records) => { const findSkylinkRecord = (records) => {
return records?.find(({ txt }) => txt?.some((entry) => isValidSkylink(entry))); // Find the last one, so people can update their domains in a non-destructive
// way by simply adding a new link. This will also allow keeping links to
// older versions for backwards compatibility.
return records
?.slice()
.reverse()
.find(({ txt }) => txt?.some((entry) => isValidSkylink(entry)));
}; };
const getSkylinkFromRecord = (record) => { const getSkylinkFromRecord = (record) => {
@ -69,7 +76,10 @@ server.use(
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
userResHeaderDecorator(headers, userReq, userRes, proxyReq, proxyRes) { userResHeaderDecorator(headers, userReq, userRes, proxyReq, proxyRes) {
if (headers.location && headers.location.match(startsWithSkylinkRegExp)) { if (headers.location && headers.location.match(startsWithSkylinkRegExp)) {
headers.location = headers.location.replace(startsWithSkylinkRegExp, `/hns/${userReq.params.name}`); headers.location = headers.location.replace(
startsWithSkylinkRegExp,
`/hns/${userReq.params.name.replace("sia://", "")}`
);
} }
return headers; return headers;
@ -81,7 +91,7 @@ server.use(
const record = findSkylinkRecord(records); const record = findSkylinkRecord(records);
if (!record) throw new Error(`No skylink found in dns records of ${req.params.name}`); if (!record) throw new Error(`No skylink found in dns records of ${req.params.name}`);
const skylink = getSkylinkFromRecord(record); const skylink = getSkylinkFromRecord(record).replace("sia://", ""); // get skylink and strip sia:// prefix
const basepath = url.resolve("/", skylink); // make the url absolute const basepath = url.resolve("/", skylink); // make the url absolute
const subpath = req.url.slice(1); // drop the leading slash const subpath = req.url.slice(1); // drop the leading slash

View File

@ -23,7 +23,7 @@ export default function HomeSamples() {
<p> <p>
Skynet includes{" "} Skynet includes{" "}
<a <a
href="https://support.siasky.net/article/hrshqsn9wz-integrating-skynet" href="https://nebulouslabs.github.io/skynet-docs"
target="_blank" target="_blank"
rel="noopener noreferrer" rel="noopener noreferrer"
className="link" className="link"
@ -34,16 +34,25 @@ export default function HomeSamples() {
<a href="https://sia.tech/docs/#skynet" target="_blank" rel="noopener noreferrer" className="link"> <a href="https://sia.tech/docs/#skynet" target="_blank" rel="noopener noreferrer" className="link">
APIs APIs
</a>{" "} </a>{" "}
that integrate seamlessly with your existing apps. You can follow this{" "} that integrate seamlessly with your existing apps. You can follow these guides to start using Skynet with{" "}
<a <a
href="https://support.siasky.net/article/vmmzyes1uy-skynet-sia-set-up" href="https://github.com/NebulousLabs/skynet-cli"
target="_blank" target="_blank"
rel="noopener noreferrer" rel="noopener noreferrer"
className="link" className="link"
> >
guide the Skynet CLI
</a>{" "} </a>{" "}
to setup a Sia Node. and{" "}
<a
href="https://blog.sia.tech/the-skynet-sdks-751b35578b20"
target="_blank"
rel="noopener noreferrer"
className="link"
>
integrate Skynet
</a>{" "}
into your application.
</p> </p>
</Fade> </Fade>