MystenLabs / walrus-sites

Walrus Sites: Decentralized Websites using Sui and Walrus.
https://docs.walrus.site/walrus-sites/intro.html
Apache License 2.0
17 stars 16 forks source link

feat(portal): 139 create server side portal #140

Closed Tzal3x closed 1 month ago

Tzal3x commented 1 month ago

Create a nextjs server that acts as a server-side walrus-sites portal. It works by combining a middleware for preprocessing the requests, and a root endpoint (defined inroute.ts) that actually contains the logic as the service worker did.

The middleware has the following role:

  1. To handle requests like http://<name>.walrus.site/path/to/file/ without throwing an error. Explanation: if you don't define a route on nextjs, the default logic is to throw an error because the /path/to/file endpoint does not exist.
  2. To delegate the whole request (including the subnames) to the route.ts in order to fetch the site resources. By default the subnames are removed from the hostname in nextjs.

In summary, the middleware is just a delegator and an error-preventer of the original url.

💁‍♂️ Review tip: the PR consists of 2 commits. I would suggest reviewing commit by commit and not the whole PR altogether.

vercel[bot] commented 1 month ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
walrus-site ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 30, 2024 8:33am
Tzal3x commented 1 month ago

Base skeleton is there. It doesn't work yet, something wrong happens with the url parsing.

Issues:

Tzal3x commented 1 month ago

To check: https://github.com/dcangulo/nextjs-subdomain-example

Tzal3x commented 1 month ago

Another article to consider: nextjs wildcard subdomains

Tzal3x commented 1 month ago

⚠️ Looks like subdomains don't work with safari.

i.e. http://docs.localhost:3000/ returns this error: Safari can't find server. Safari can't find the server docs.localhost

Tzal3x commented 1 month ago

⚠️ There seems to be an infinite loop occurring when I'm running an instance of the server's production build (pnpm run start). It doesn't occur on development mode (pnpm run dev).

Sample output:

...
Trying to extract the walrus link from: http://localhost:3000/service-worker.js
Trying to extract the sui link from: http://localhost:3000/service-worker.js
Trying to extract the walrus link from: http://localhost:3000/service-worker.js
Trying to extract the sui link from: http://localhost:3000/service-worker.js
Trying to extract the walrus link from: http://localhost:3000/service-worker.js
Trying to extract the sui link from: http://localhost:3000/service-worker.js
Trying to extract the walrus link from: http://localhost:3000/service-worker.js
Trying to extract the sui link from: http://localhost:3000/service-worker.js
Trying to extract the walrus link from: http://localhost:3000/service-worker.js
Trying to extract the sui link from: http://localhost:3000/service-worker.js
...
Tzal3x commented 1 month ago

⚠️ There seems to be an infinite loop occurring when I'm running an instance of the server's production build (pnpm run start). It doesn't occur on development mode (pnpm run dev).

🎉 Fixed - I created this post that explains it.

Tzal3x commented 1 month ago

did you add the settings to .editorconfig? if so, can you commit them?

@giac-mysten I actually just removed the prettierrc file because it was redundant after I compared them.