Files
jayjennings 3f6dff5f24
CI / Lint, typecheck, test, build (push) Canceled after 0s
CI / End-to-end tests (push) Canceled after 0s
feat: implement permissions and actions management
- Add permissions logic for status options in corrective actions.
- Create tests for permissions functionality.
- Implement queries for user authentication and actions management.
- Develop Actions page to display and manage corrective actions.
- Create authentication pages for login, setup, and password reset.
- Add IncidentDetail page to view incident details and associated actions.
- Implement Settings page for user management and password changes.
2026-10-06 11:20:44 -07:00

50 lines
1.9 KiB
TypeScript

import { serve } from '@hono/node-server'
import { serveStatic } from '@hono/node-server/serve-static'
import { existsSync } from 'node:fs'
import { join } from 'node:path'
import { createApp } from './app.ts'
import { loadConfig } from './config.ts'
import { openDatabase } from './db/client.ts'
import { createMailer } from './mail.ts'
import { Notifier } from './notifications.ts'
import { FileStorage } from './storage.ts'
const config = loadConfig()
const database = await openDatabase(config.databaseUrl)
const notifier = new Notifier(database.db, createMailer(config), config)
const app = createApp({ db: database.db, config, notifier, storage: new FileStorage(config.uploadDir) })
// Hourly check for corrective actions that are due or overdue; each gets at most one reminder a day.
const sendReminders = () => notifier.sendDueReminders().catch((error) => console.error('[reminders] failed:', error))
const reminderTimer = setInterval(sendReminders, 60 * 60 * 1000)
setTimeout(sendReminders, 30_000).unref()
// In production the server also serves the built web app.
if (existsSync(join(config.staticDir, 'index.html'))) {
app.use(
'/*',
serveStatic({
root: config.staticDir,
onFound: (path, c) => {
if (path.includes('/assets/')) c.header('Cache-Control', 'public, max-age=31536000, immutable')
},
}),
)
app.get('*', serveStatic({ path: join(config.staticDir, 'index.html') })) // client-side routes
}
const server = serve({ fetch: app.fetch, port: config.port }, ({ port }) => {
console.log(`Open SafetyLog EHS listening on port ${port}, public URL ${config.publicUrl} (database: ${config.databaseUrl.replace(/\/\/[^@]*@/, '//***@')})`)
})
for (const signal of ['SIGINT', 'SIGTERM'] as const) {
process.on(signal, () => {
clearInterval(reminderTimer)
server.close(async () => {
await notifier.flush()
await database.close()
process.exit(0)
})
})
}