2020-11-15 11:41:50 +01:00
|
|
|
const functions = require('firebase-functions');
|
|
|
|
const admin = require('firebase-admin')
|
|
|
|
|
|
|
|
const { configureApplication } = require('./lib/app')
|
2020-11-15 21:33:16 +01:00
|
|
|
const {
|
|
|
|
createRouteLogger,
|
|
|
|
createErrorLogger,
|
|
|
|
createAppLogger,
|
|
|
|
} = require('./logger')
|
2020-11-15 11:41:50 +01:00
|
|
|
|
|
|
|
admin.initializeApp()
|
|
|
|
|
|
|
|
const isDevelopment = process.env.NODE_ENV === 'development'
|
|
|
|
|
2020-11-15 21:33:16 +01:00
|
|
|
const db = admin.database()
|
|
|
|
|
|
|
|
const appLogger = createAppLogger({ db })
|
|
|
|
const errorLogger = createErrorLogger({ db })
|
|
|
|
const routeLogger = createRouteLogger({ db })
|
2020-11-15 11:41:50 +01:00
|
|
|
const corsOptions = isDevelopment ? {
|
|
|
|
origin: 'http://localhost:5000',
|
|
|
|
} : null
|
|
|
|
|
|
|
|
const app = configureApplication({
|
|
|
|
rateLimitEnabled: false,
|
|
|
|
corsOptions,
|
2020-11-15 21:33:16 +01:00
|
|
|
appLogger,
|
|
|
|
errorLogger,
|
|
|
|
routeLogger,
|
2020-11-15 11:41:50 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
exports.app = functions.https.onRequest(app)
|
|
|
|
|
|
|
|
|