Scenario generator for vore roleplay and story ideas.
https://scenario-generator.deliciousreya.net/responses
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.8 KiB
51 lines
1.8 KiB
import { Database } from './db/database';
|
|
import { discordRouter } from './discord/router';
|
|
import { createCors, Router, IRequestStrict } from 'itty-router';
|
|
import { webRouter } from './web/router';
|
|
|
|
export interface Env {
|
|
readonly BASE_URL: string;
|
|
readonly CREDITS_URL: string;
|
|
readonly DISCORD_APP_ID: string;
|
|
readonly DISCORD_APP_SECRET: string;
|
|
readonly DISCORD_PUBLIC_KEY: string;
|
|
readonly DISCORD_DEV_GUILD_IDS: string;
|
|
readonly DB: D1Database;
|
|
}
|
|
|
|
const { preflight, corsify } = createCors();
|
|
const discord = discordRouter('/discord')
|
|
const web = webRouter('/')
|
|
|
|
const router = Router<IRequestStrict, [env: Env, db: Database, ctx: ExecutionContext]>()
|
|
.all('*', preflight)
|
|
.all('/discord/*', discord.handle.bind(discord))
|
|
.all('/*', web.handle.bind(web))
|
|
.all('*', (_req, _env, _db, _ctx) => null);
|
|
|
|
// noinspection JSUnusedGlobalSymbols
|
|
export default {
|
|
async fetch(req: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
|
|
const startTime = performance.now()
|
|
return router.handle(req, env, new Database(env.DB), ctx).then((result) => {
|
|
if (result instanceof Response) {
|
|
return result;
|
|
} else if (typeof result === 'string') {
|
|
const headers = new Headers()
|
|
headers.set("Content-Type", "text/html")
|
|
return new Response(result, { status: 200, statusText: 'OK', headers});
|
|
} else if (typeof result === 'object' || Array.isArray(result)) {
|
|
return Response.json(result, { status: 200, statusText: 'OK' });
|
|
} else {
|
|
return new Response('Not Found', { status: 404, statusText: 'Not Found' });
|
|
}
|
|
}).catch((reason) => {
|
|
return new Response(`Failed: ${reason}`, { status: 500, statusText: 'Internal Server Error' });
|
|
}).then((response) => {
|
|
return corsify(response);
|
|
}).finally(() => {
|
|
const endTime = performance.now()
|
|
console.info(`request runtime: ${endTime - startTime}`)
|
|
});
|
|
}
|
|
};
|
|
|