mirror of
https://github.com/hackku21/loc-chain-backend.git
synced 2024-10-27 20:34:03 +00:00
Add initial firebase connection logic
This commit is contained in:
parent
c56f0706a4
commit
b0123afee8
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal 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/
|
8
.idea/loc-chain-backend.iml
Normal file
8
.idea/loc-chain-backend.iml
Normal 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
8
.idea/modules.xml
Normal 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
6
.idea/vcs.xml
Normal 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>
|
@ -10,11 +10,11 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@extollo/cli": "^0.4.1",
|
"@extollo/cli": "^0.4.1",
|
||||||
"@extollo/di": "^0.4.2",
|
"@extollo/di": "^0.4.2",
|
||||||
"@extollo/i18n": "^0.1.1",
|
|
||||||
"@extollo/lib": "^0.1.2",
|
"@extollo/lib": "^0.1.2",
|
||||||
"@extollo/orm": "^0.1.1",
|
"@extollo/orm": "^0.1.1",
|
||||||
"@extollo/util": "^0.3.1",
|
"@extollo/util": "^0.3.1",
|
||||||
"copyfiles": "^2.4.1",
|
"copyfiles": "^2.4.1",
|
||||||
|
"firebase-admin": "^9.6.0",
|
||||||
"typescript": "^4.1.3"
|
"typescript": "^4.1.3"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
984
pnpm-lock.yaml
984
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
@ -1,17 +1,17 @@
|
|||||||
import {Config, Controllers, HTTPServer, Files, Middlewares, Routing, Unit} from '@extollo/lib'
|
import {Config, Controllers, HTTPServer, Files, Middlewares, Routing, Unit} from '@extollo/lib'
|
||||||
import {Database, Models} from "@extollo/orm";
|
import {Database, Models} from "@extollo/orm";
|
||||||
import {CommandLine} from "@extollo/cli";
|
import {CommandLine} from "@extollo/cli";
|
||||||
import {Internationalization} from "@extollo/i18n";
|
import {FirebaseUnit} from "./app/units/FirebaseUnit";
|
||||||
|
|
||||||
export const Units = [
|
export const Units = [
|
||||||
Config,
|
Config,
|
||||||
|
FirebaseUnit,
|
||||||
Files,
|
Files,
|
||||||
CommandLine,
|
CommandLine,
|
||||||
Controllers,
|
Controllers,
|
||||||
Middlewares,
|
Middlewares,
|
||||||
Database,
|
Database,
|
||||||
Models,
|
Models,
|
||||||
Internationalization,
|
|
||||||
|
|
||||||
Routing,
|
Routing,
|
||||||
HTTPServer,
|
HTTPServer,
|
||||||
|
@ -1,5 +1,15 @@
|
|||||||
import { env } from '@extollo/lib'
|
import { env } from '@extollo/lib'
|
||||||
|
import * as fs from "fs"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: env('APP_NAME', 'Extollo'),
|
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'),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,16 @@
|
|||||||
import {Controller, view, Session} from '@extollo/lib';
|
import {Controller, view, Session} from '@extollo/lib';
|
||||||
import {Inject, Injectable} from "@extollo/di";
|
import {Inject, Injectable} from "@extollo/di";
|
||||||
import {Locale} from "@extollo/i18n"
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class Home extends Controller {
|
export class Home extends Controller {
|
||||||
@Inject()
|
@Inject()
|
||||||
protected readonly session!: Session;
|
protected readonly session!: Session;
|
||||||
|
|
||||||
@Inject()
|
|
||||||
protected readonly locale!: Locale;
|
|
||||||
|
|
||||||
public welcome() {
|
public welcome() {
|
||||||
this.session.set('app_visits', this.session.get('app_visits', 0) + 1)
|
this.session.set('app_visits', this.session.get('app_visits', 0) + 1)
|
||||||
|
|
||||||
return view('welcome', {
|
return view('welcome', {
|
||||||
app_visits: this.session.get('app_visits'),
|
app_visits: this.session.get('app_visits'),
|
||||||
locale: this.locale.helper(),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
37
src/app/units/FirebaseUnit.ts
Normal file
37
src/app/units/FirebaseUnit.ts
Normal 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() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user