Skip to content

Instantly share code, notes, and snippets.

@bingxin666
Created December 28, 2024 11:14
Show Gist options
  • Select an option

  • Save bingxin666/05def6dd12a706b79609acd5aec8e047 to your computer and use it in GitHub Desktop.

Select an option

Save bingxin666/05def6dd12a706b79609acd5aec8e047 to your computer and use it in GitHub Desktop.
用于部署到 Workers 上实现联邦的 JS 文件
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