Skip to content

Commit

Permalink
fix entrypoint order of operations
Browse files Browse the repository at this point in the history
  • Loading branch information
devinivy committed Mar 13, 2024
1 parent 2a598bc commit 2516da1
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
envToCfg,
envToSecrets,
OzoneService,
Database,
} = require('@atproto/ozone')
const pkg = require('@atproto/ozone/package.json')

Expand All @@ -15,15 +16,20 @@ async function main() {
const frontendHandler = frontend.getRequestHandler()
await frontend.prepare()
// backend
const migrate = process.env.OZONE_DB_MIGRATE === '1'
const env = readEnv()
env.version ??= pkg.version
const config = envToCfg(env)
const secrets = envToSecrets(env)
const ozone = await OzoneService.create(config, secrets)
const migrate = process.env.OZONE_DB_MIGRATE === '1'
if (migrate) {
await ozone.ctx.db.migrateToLatestOrThrow()
const db = new Database({
url: config.db.postgresUrl,
schema: config.db.postgresSchema,
})
await db.migrateToLatestOrThrow()
await db.close()
}
const ozone = await OzoneService.create(config, secrets)
// setup handlers
ozone.app.get('/.well-known/ozone-metadata.json', (_req, res) => {
return res.json({
Expand All @@ -42,4 +48,4 @@ async function main() {
httpLogger.info(`Ozone is running at http://localhost:${addr.port}`)
}

main()
main().catch(console.error)

0 comments on commit 2516da1

Please sign in to comment.