Skip to content

Commit

Permalink
prettier things
Browse files Browse the repository at this point in the history
  • Loading branch information
darora committed Feb 7, 2022
1 parent c053c0d commit 9850273
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 41 deletions.
9 changes: 2 additions & 7 deletions src/plugins/postgrest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@ declare module 'fastify' {
}

async function getPostgrestClient(request: FastifyRequest, jwt: string): Promise<PostgrestClient> {
const {
anonKey,
isMultitenant,
postgrestURL,
postgrestURLSuffix,
xForwardedHostRegExp,
} = getConfig()
const { anonKey, isMultitenant, postgrestURL, postgrestURLSuffix, xForwardedHostRegExp } =
getConfig()
let url = postgrestURL
let apiKey = anonKey
if (isMultitenant && xForwardedHostRegExp) {
Expand Down
6 changes: 5 additions & 1 deletion src/routes/bucket/createBucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ export default async function routes(fastify: FastifyInstance) {
.send(createResponse('The key contains invalid characters', '400', 'Invalid key'))
}

const { data: results, error, status } = await request.postgrest
const {
data: results,
error,
status,
} = await request.postgrest
.from<Bucket>('buckets')
.insert(
[
Expand Down
6 changes: 5 additions & 1 deletion src/routes/bucket/getAllBuckets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ export default async function routes(fastify: FastifyInstance) {
},
async (request, response) => {
// get list of all buckets
const { data: results, error, status } = await request.postgrest
const {
data: results,
error,
status,
} = await request.postgrest
.from<Bucket>('buckets')
.select('id, name, public, owner, created_at, updated_at')

Expand Down
6 changes: 5 additions & 1 deletion src/routes/object/copyObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ export default async function routes(fastify: FastifyInstance) {
owner,
})
request.log.info({ origObject }, 'newObject')
const { data: results, error, status } = await request.postgrest
const {
data: results,
error,
status,
} = await request.postgrest
.from<Obj>('objects')
.insert([newObject], {
returning: 'minimal',
Expand Down
6 changes: 5 additions & 1 deletion src/routes/object/listObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ export default async function routes(fastify: FastifyInstance) {
request.log.info(request.body)
request.log.info(`searching for %s`, prefix)

const { data: results, error, status } = await request.postgrest
const {
data: results,
error,
status,
} = await request.postgrest
.rpc('search', {
prefix,
bucketname: bucketName,
Expand Down
60 changes: 30 additions & 30 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getConfig } from './utils/config'
import { runMultitenantMigrations, runMigrations } from './utils/migrate'
import { cacheTenantConfigsFromDbAndRunMigrations } from './utils/tenant'

let logger = pino({
const logger = pino({
formatters: {
level(label) {
return { level: label }
Expand All @@ -19,36 +19,36 @@ let logger = pino({

const exposeDocs = true

; (async () => {
const { isMultitenant } = getConfig()
if (isMultitenant) {
await runMultitenantMigrations()
await cacheTenantConfigsFromDbAndRunMigrations()

const adminApp: FastifyInstance<Server, IncomingMessage, ServerResponse> = buildAdmin({
logger,
})

try {
await adminApp.listen(5001, '0.0.0.0')
} catch (err) {
adminApp.log.error(err)
process.exit(1)
}
} else {
await runMigrations()
}
;(async () => {
const { isMultitenant } = getConfig()
if (isMultitenant) {
await runMultitenantMigrations()
await cacheTenantConfigsFromDbAndRunMigrations()

const app: FastifyInstance<Server, IncomingMessage, ServerResponse> = build({
const adminApp: FastifyInstance<Server, IncomingMessage, ServerResponse> = buildAdmin({
logger,
exposeDocs,
})

app.listen(5000, '0.0.0.0', (err, address) => {
if (err) {
console.error(err)
process.exit(1)
}
console.log(`Server listening at ${address}`)
})
})()
try {
await adminApp.listen(5001, '0.0.0.0')
} catch (err) {
adminApp.log.error(err)
process.exit(1)
}
} else {
await runMigrations()
}

const app: FastifyInstance<Server, IncomingMessage, ServerResponse> = build({
logger,
exposeDocs,
})

app.listen(5000, '0.0.0.0', (err, address) => {
if (err) {
console.error(err)
process.exit(1)
}
console.log(`Server listening at ${address}`)
})
})()

0 comments on commit 9850273

Please sign in to comment.