Created
December 28, 2024 11:14
-
-
Save bingxin666/05def6dd12a706b79609acd5aec8e047 to your computer and use it in GitHub Desktop.
用于部署到 Workers 上实现联邦的 JS 文件
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const HOMESERVER_URL = "https://matrix.example.com"; | |
| const IDENTITY_SERVER_URL = "https://vector.im"; | |
| const FEDERATION_SERVER = "matrix.example.com:443"; | |
| export default { | |
| async fetch(request) { | |
| const path = new URL(request.url).pathname; | |
| switch (path) { | |
| case "/.well-known/matrix/client": | |
| return new Response( | |
| `{"m.homeserver": {"base_url": "${HOMESERVER_URL}"},"m.identity_server": {"base_url": "${IDENTITY_SERVER_URL}"}}`, | |
| { | |
| status: 200, | |
| headers: { | |
| "Access-Control-Allow-Origin": "*", | |
| "Content-Type": "application/json", | |
| }, | |
| } | |
| ); | |
| case "/.well-known/matrix/server": | |
| return new Response(`{"m.server": "${FEDERATION_SERVER}"}`, { | |
| status: 200, | |
| headers: { | |
| "Access-Control-Allow-Origin": "*", | |
| "Content-Type": "application/json", | |
| }, | |
| }); | |
| default: | |
| return new Response("Invalid request", { | |
| status: 400, | |
| headers: { | |
| "Access-Control-Allow-Origin": "*", | |
| "Content-Type": "text/plain", | |
| }, | |
| }); | |
| } | |
| }, | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment