Skip to content

Commit 5c5c1c8

Browse files
committed
feat: add lib boolean
1 parent cac0550 commit 5c5c1c8

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

src/lib/boolean.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { env } from '~/config/env'
2+
3+
/**
4+
* Check if storage is enabled
5+
*/
6+
export function storageExists(): boolean {
7+
switch (env.STORAGE_PROVIDER) {
8+
case 'minio':
9+
return Boolean(
10+
env.STORAGE_HOST &&
11+
env.STORAGE_BUCKET_NAME &&
12+
env.STORAGE_ACCESS_KEY &&
13+
env.STORAGE_SECRET_KEY
14+
)
15+
16+
case 's3':
17+
return Boolean(env.STORAGE_BUCKET_NAME && env.STORAGE_ACCESS_KEY && env.STORAGE_SECRET_KEY)
18+
19+
case 'gcs':
20+
return Boolean(env.STORAGE_ACCESS_KEY && env.STORAGE_BUCKET_NAME && env.STORAGE_FILEPATH)
21+
22+
default:
23+
return false
24+
}
25+
}

src/main.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
import http from 'http'
2+
import { initDatabase } from './app/database/connection'
23
import { App } from './config/app'
34
import { env } from './config/env'
5+
import { storage } from './config/storage'
6+
import { storageExists } from './lib/boolean'
47
import { httpHandle } from './lib/http/handle'
5-
import { initDatabase } from './app/database/connection'
68

79
function bootstrap() {
810
const port = env.APP_PORT
911
const app = new App().create
1012
const server = http.createServer(app)
13+
const isStorageEnabled = storageExists()
1114

15+
// initial database
1216
initDatabase()
1317

18+
// initial storage
19+
if (isStorageEnabled) {
20+
storage.initialize()
21+
}
22+
1423
// http handle
1524
const { onError, onListening } = httpHandle(server, port)
1625

0 commit comments

Comments
 (0)