28 lines
920 B
TypeScript
28 lines
920 B
TypeScript
import { customAlphabet } from '@nanoid';
|
|
import { STATUS_CODE, STATUS_TEXT, StatusCode } from '@std/http';
|
|
|
|
import config from '~config';
|
|
|
|
// Using custom alphabet to exclude - and _
|
|
const alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
|
const nanoid = customAlphabet(alphabet, 20);
|
|
|
|
const genericResponse = (status: StatusCode, customText = '') =>
|
|
new Response(customText || STATUS_TEXT[status], { status: status, statusText: STATUS_TEXT[status] });
|
|
|
|
Deno.serve({ port: config.api.port }, async (req) => {
|
|
const [urlPath, tempQ] = req.url.split('?');
|
|
const path = (urlPath.split('api/')[1] ?? '').toLowerCase().trim();
|
|
console.log(urlPath, path);
|
|
|
|
if (req.method === 'GET') {
|
|
// handle all gets
|
|
} else if (path === '/auth') {
|
|
return new Response(nanoid());
|
|
} else {
|
|
// handle auth then all other shiz
|
|
}
|
|
|
|
return genericResponse(STATUS_CODE.NotImplemented);
|
|
});
|