-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver-web.ts
More file actions
33 lines (28 loc) · 1.01 KB
/
Copy pathserver-web.ts
File metadata and controls
33 lines (28 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import express from 'express'
import cors from 'cors'
import { getDb } from './src/main/db/connection.ts'
import { itemsRouter } from './src/main/api/items.ts'
import { searchRouter } from './src/main/api/search.ts'
import { settingsRouter } from './src/main/api/settings.ts'
import { spacesRouter } from './src/main/api/spaces.ts'
import { pushRouter, sendPushToAll } from './src/main/api/push.ts'
const db = getDb()
const app = express()
app.use(cors({ origin: true, credentials: true }))
app.use(express.json())
app.get('/health', (_req, res) => {
res.json({ ok: true })
})
app.use('/api/items', itemsRouter(db, {
onInboxItem: (title: string) => {
sendPushToAll(db, 'Cortex — new in Inbox', title || 'New item captured')
}
}))
app.use('/api/settings', settingsRouter(db))
app.use('/api/spaces', spacesRouter(db))
app.use('/api/push', pushRouter(db))
app.use('/api', searchRouter(db))
const PORT = 8000
app.listen(PORT, '127.0.0.1', () => {
console.log(`Cortex API server running on http://127.0.0.1:${PORT}`)
})