Skip to content

Commit

Permalink
从 cf worker 变成纯 pages function
Browse files Browse the repository at this point in the history
* remove unused configuration files and add TypeScript configuration for functions

* test

* remove wrangler.toml configuration file
  • Loading branch information
AsenHu authored Oct 31, 2024
1 parent 5ba5ae3 commit b34defa
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 2,924 deletions.
12 changes: 0 additions & 12 deletions .editorconfig

This file was deleted.

6 changes: 0 additions & 6 deletions .prettierrc

This file was deleted.

38 changes: 38 additions & 0 deletions functions/.well-known/matrix/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
interface Client {
"m.homeserver": {
"base_url": string;
};
"org.matrix.msc3575.proxy": {
"url": string;
};
}

export const onRequestGet: PagesFunction = async ({ request }) => {
const continent: string = (request.cf.continent as string) || 'default';
let tag: string;
if (continent === 'AS') {
const country = request.cf.country || 'default';
if (country === 'CN') {
tag = 'cn';
} else {
tag = continent.toLowerCase();
}
} else {
tag = continent.toLowerCase();
}

const r: Client = {
"m.homeserver": {
"base_url": `https://${tag}-matrix-client.nekos.chat`
},
"org.matrix.msc3575.proxy": {
"url": `https://${tag}-slidingsync.nekos.chat`
}
}
return new Response(JSON.stringify(r), {
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json'
}
});
}
28 changes: 28 additions & 0 deletions functions/.well-known/matrix/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
interface Server {
"m.server": string;
}

export const onRequestGet: PagesFunction = async ({ request }) => {
const continent: string = (request.cf.continent as string) || 'default';
let tag: string;
if (continent === 'AS') {
const country = request.cf.country || 'default';
if (country === 'CN') {
tag = 'cn';
} else {
tag = continent.toLowerCase();
}
} else {
tag = continent.toLowerCase();
}

const r: Server = {
"m.server": `${tag}-matrix-federation.nekos.chat:443`
}
return new Response(JSON.stringify(r), {
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json'
}
});
}
15 changes: 15 additions & 0 deletions functions/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"lib": [
"esnext"
],
"types": [
"@cloudflare/workers-types"
]
},
"include": [
".well-known/**/*.ts"
]
}
Loading

0 comments on commit b34defa

Please sign in to comment.