Stub out all SSR, built login page

This commit is contained in:
Ean Milligan
2026-04-10 02:37:13 -04:00
parent 318f096d33
commit 5b28f36bef
4 changed files with 77 additions and 4 deletions

23
mod.ts
View File

@@ -1,10 +1,14 @@
import { customAlphabet } from '@nanoid';
import { STATUS_CODE, STATUS_TEXT, StatusCode } from '@std/http';
import { STATUS_CODE, STATUS_TEXT, StatusCode } from '@std/http/status';
import config from '~config';
import dbClient from 'db/client.ts';
import buildPage from './ssr/buildPage.ts';
import buildLogin from './ssr/buildLogin.ts';
import buildHome from './ssr/buildHome.ts';
// Using custom alphabet to exclude - and _
const alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
const nanoid = customAlphabet(alphabet, 20);
@@ -29,12 +33,23 @@ Deno.serve({ port: config.api.port }, async (req) => {
let failed = false;
if (req.method === 'GET') {
if (path === '/home') {
if (path === '') {
const redirectHeaders = new Headers();
redirectHeaders.set('Location', '/api/home');
return genericResponse(STATUS_CODE.PermanentRedirect, undefined, redirectHeaders);
} else if (path === '/home') {
// SSR "login page"
return genericResponse(STATUS_CODE.Unauthorized, 'Please sign in.');
return buildPage(buildLogin);
} else if (path.startsWith('/home/')) {
// SSR "home page"
return genericResponse(STATUS_CODE.NotImplemented, 'WIP');
const userId = path.replace('/home/', '');
const userMatch = await dbClient.query('SELECT id FROM users WHERE id = ?', [userId]).catch(() => {
failed = true;
});
if (failed) return buildPage("Couldn't read DB. Please try again.");
if (!userMatch.length) return buildPage('User ID does not exist. Please click on the page header to go back to the sign in page.');
return buildPage(buildHome(userId));
} else if (path.startsWith('/read/')) {
const planId = path.replace('/read/', '');