60 lines
1.4 KiB
TypeScript
60 lines
1.4 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,
|
|
fetchBookmark,
|
|
listUserTags,
|
|
createUserTag,
|
|
listBookmarkTags,
|
|
} 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/bookmarks/:id": {
|
|
GET: authenticated(fetchBookmark),
|
|
DELETE: authenticated(deleteUserBookmark),
|
|
OPTIONS: preflightHandler({
|
|
allowedMethods: ["GET", "POST", "DELETE", "OPTIONS"],
|
|
allowedHeaders: ["Accept"],
|
|
}),
|
|
},
|
|
"/api/bookmarks/:id/tags": {
|
|
GET: authenticated(listBookmarkTags),
|
|
},
|
|
"/api/tags": {
|
|
GET: authenticated(listUserTags),
|
|
POST: authenticated(createUserTag),
|
|
},
|
|
},
|
|
|
|
port: 8080,
|
|
})
|
|
}
|
|
|
|
main()
|