Add initial firebase connection logic

This commit is contained in:
Garrett Mills 2021-04-09 21:26:57 -05:00
parent c56f0706a4
commit b0123afee8
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246
10 changed files with 1039 additions and 33 deletions

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/loc-chain-backend.iml" filepath="$PROJECT_DIR$/.idea/loc-chain-backend.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -10,11 +10,11 @@
"dependencies": {
"@extollo/cli": "^0.4.1",
"@extollo/di": "^0.4.2",
"@extollo/i18n": "^0.1.1",
"@extollo/lib": "^0.1.2",
"@extollo/orm": "^0.1.1",
"@extollo/util": "^0.3.1",
"copyfiles": "^2.4.1",
"firebase-admin": "^9.6.0",
"typescript": "^4.1.3"
},
"scripts": {

File diff suppressed because it is too large Load Diff

View File

@ -1,17 +1,17 @@
import {Config, Controllers, HTTPServer, Files, Middlewares, Routing, Unit} from '@extollo/lib'
import {Database, Models} from "@extollo/orm";
import {CommandLine} from "@extollo/cli";
import {Internationalization} from "@extollo/i18n";
import {FirebaseUnit} from "./app/units/FirebaseUnit";
export const Units = [
Config,
FirebaseUnit,
Files,
CommandLine,
Controllers,
Middlewares,
Database,
Models,
Internationalization,
Routing,
HTTPServer,

View File

@ -1,5 +1,15 @@
import { env } from '@extollo/lib'
import * as fs from "fs"
export default {
name: env('APP_NAME', 'Extollo'),
firebase: {
credentials: JSON.parse(
fs.readFileSync(env('FIREBASE_CREDENTIALS'))
.toString('utf-8')
),
defaultRTDB: env('FIREBASE_DEFAULT_RTDB', 'https://loc-chain-default-rtdb.firebaseio.com'),
}
}

View File

@ -1,21 +1,16 @@
import {Controller, view, Session} from '@extollo/lib';
import {Inject, Injectable} from "@extollo/di";
import {Locale} from "@extollo/i18n"
@Injectable()
export class Home extends Controller {
@Inject()
protected readonly session!: Session;
@Inject()
protected readonly locale!: Locale;
public welcome() {
this.session.set('app_visits', this.session.get('app_visits', 0) + 1)
return view('welcome', {
app_visits: this.session.get('app_visits'),
locale: this.locale.helper(),
})
}
}

View File

@ -0,0 +1,37 @@
import {Singleton, Inject} from "@extollo/di"
import {Unit, Logging, Config} from "@extollo/lib"
import * as firebase from "firebase-admin"
/**
* FirebaseUnit Unit
* ---------------------------------------
* Fetch credentials from config and setup the firebase-admin connection.
*/
@Singleton()
export class FirebaseUnit extends Unit {
protected _firebase = firebase;
@Inject()
protected readonly logging!: Logging
@Inject()
protected readonly config!: Config
get() {
return this._firebase
}
/** Called on app start. */
public async up() {
this.logging.info('Initializing Firebase application credentials...')
this._firebase.initializeApp({
credential: firebase.credential.cert(this.config.get('app.firebase.credentials')),
databaseURL: this.config.get('app.firebase.defaultRTDB'),
})
}
/** Called on app shutdown. */
public async down() {
}
}