43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import { authenticated, login, logout, signUp } from "./auth/auth.ts"
|
|
import { startBackgroundSessionCleanup } from "./auth/session.ts"
|
|
import { insertDemoBookmarks } from "./bookmark/bookmark.ts"
|
|
import { addBookmark, listUserBookmarks, deleteUserBookmark } from "./bookmark/handlers.ts"
|
|
import { migrateDatabase } from "./database.ts"
|
|
import { httpHandler, preflightHandler } from "./http-handler.ts"
|
|
import { createDemoUser } from "./user/user.ts"
|
|
|
|
async function main() {
|
|
migrateDatabase()
|
|
const user = await createDemoUser()
|
|
insertDemoBookmarks(user)
|
|
startBackgroundSessionCleanup()
|
|
|
|
Bun.serve({
|
|
routes: {
|
|
"/api/login": {
|
|
POST: httpHandler(login),
|
|
},
|
|
"/api/sign-up": {
|
|
POST: httpHandler(signUp),
|
|
},
|
|
"/api/logout": {
|
|
POST: authenticated(logout),
|
|
},
|
|
"/api/bookmarks": {
|
|
GET: authenticated(listUserBookmarks),
|
|
POST: authenticated(addBookmark),
|
|
},
|
|
"/api/bookmark/:id": {
|
|
DELETE: authenticated(deleteUserBookmark),
|
|
OPTIONS: preflightHandler({
|
|
allowedMethods: ["GET", "POST", "DELETE", "OPTIONS"],
|
|
}),
|
|
},
|
|
},
|
|
|
|
port: 8080,
|
|
})
|
|
}
|
|
|
|
main()
|