diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 66f0cfcf..909abc86 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,7 +11,7 @@ jobs: - name: Use Node.js uses: actions/setup-node@v1 with: - node-version: 12.x + node-version: 14.6 - name: Install dependencies run: yarn diff --git a/.gitignore b/.gitignore index 43f25aa7..6a4f2eb0 100644 --- a/.gitignore +++ b/.gitignore @@ -78,3 +78,4 @@ docker/data # Cache files __pycache__ /.idea/ +/venv/ diff --git a/docker-compose.yml b/docker-compose.yml index 71d0671f..e1748e85 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -55,7 +55,6 @@ services: - 80 depends_on: - docker-host - - health-check - handshake-api handshake: @@ -115,7 +114,6 @@ services: expose: - 3100 depends_on: - - docker-host + - caddy - handshake - handshake-api - - caddy diff --git a/handshake-api/index.js b/handshake-api/index.js index 6c00d2f4..87b5a09a 100644 --- a/handshake-api/index.js +++ b/handshake-api/index.js @@ -19,7 +19,8 @@ const 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 response = await client.execute("getnameresource", [name]); @@ -31,7 +32,13 @@ const getDomainRecords = async (name) => { }; 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) => { @@ -69,7 +76,10 @@ server.use( // eslint-disable-next-line no-unused-vars userResHeaderDecorator(headers, userReq, userRes, proxyReq, proxyRes) { 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;