main
Ethan Niser 2023-09-14 20:07:28 +00:00 committed by GitHub
parent 1acd519951
commit 83a37d31df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 47 additions and 25 deletions

Binary file not shown.

@ -33,6 +33,7 @@
"drizzle-orm": "^0.28.6",
"drizzle-typebox": "^0.1.1",
"elysia": "^0.6.22",
"elysia-autoroutes": "^0.2.2",
"lucia": "^2.6.0",
"pino-pretty": "^10.2.0",
"zod": "^3.22.2"

@ -22,6 +22,12 @@ export const auth = lucia({
key: "user_key",
session: "user_session",
}),
getUserAttributes: (data) => {
return {
username: data.username,
};
},
});
export type Auth = typeof auth;

@ -8,13 +8,13 @@ export function TodoItem({ content, completed, id }: Todo) {
<input
type="checkbox"
checked={completed}
hx-post={`/todos/toggle/${id}`}
hx-post={`/api/todos/toggle/${id}`}
hx-swap="outerHTML"
hx-target="closest div"
/>
<button
class="text-red-500"
hx-delete={`/todos/${id}`}
hx-delete={`/api/todos/${id}`}
hx-swap="outerHTML"
hx-target="closest div"
>
@ -39,7 +39,7 @@ export function TodoForm() {
return (
<form
class="flex flex-row space-x-3"
hx-post="/todos"
hx-post="/api/todos"
hx-swap="beforebegin"
_="on submit target.reset()"
>

@ -38,3 +38,9 @@ export const ctx = new Elysia({
// );
// });
// .onError(({ log, error }) => log.error(error));
export type ElysiaApp = typeof ctx;
export type GetHandler = Parameters<typeof ctx.get>[1];
export type PostHandler = Parameters<typeof ctx.post>[1];
export type PutHandler = Parameters<typeof ctx.put>[1];
export type DelHandler = Parameters<typeof ctx.delete>[1];

@ -2,6 +2,7 @@ import { sqliteTable, text, blob } from "drizzle-orm/sqlite-core";
export const user = sqliteTable("user", {
id: text("id").primaryKey(),
username: text("username").notNull(),
// other user attributes
});

@ -0,0 +1 @@
import Html from "@kitajs/html";

@ -0,0 +1,7 @@
import Elysia from "elysia";
import { todosService } from "./todos";
export const api = new Elysia({
name: "@app/api",
prefix: "/api",
}).use(todosService);

@ -1,8 +1,8 @@
import { Elysia } from "elysia";
import { swagger } from "@elysiajs/swagger";
import { staticPlugin } from "@elysiajs/static";
import { todosService } from "./handlers/todos";
import { pages } from "./pages";
import { api } from "./handlers";
import { autoroutes } from "elysia-autoroutes";
const app = new Elysia({
name: "@app/main",
@ -10,8 +10,12 @@ const app = new Elysia({
// @ts-expect-error idk why this is broken
.use(swagger())
.use(staticPlugin())
.use(todosService)
.use(pages)
.use(api)
.use(
autoroutes({
routesDir: "./pages",
})
)
.listen(3000);
export type App = typeof app;

@ -1,21 +1,15 @@
import { Elysia } from "elysia";
import { ctx } from "../context";
import { GetHandler } from "../context";
import Html from "@kitajs/html";
import { BaseHtml } from "../components/base";
export const pages = new Elysia({
name: "@app/pages",
})
.use(ctx)
.get("/", ({ html }) =>
html(
<BaseHtml>
<div
class="flex w-full h-screen justify-center items-center"
hx-get="/todos"
hx-swap="innerHTML"
hx-trigger="load"
/>
</BaseHtml>
)
export const get: GetHandler = ({ html }) =>
html(
<BaseHtml>
<div
class="flex w-full h-screen justify-center items-center"
hx-get="/api/todos"
hx-swap="innerHTML"
hx-trigger="load"
/>
</BaseHtml>
);

@ -1,6 +1,8 @@
/// <reference types="lucia" />
declare namespace Lucia {
type Auth = import("../auth/index").Auth;
type DatabaseUserAttributes = {};
type DatabaseUserAttributes = {
username: string;
};
type DatabaseSessionAttributes = {};
}