mirror of
https://github.com/hackku21/loc-chain-backend.git
synced 2026-03-02 03:40:09 +00:00
Import Extollo framework
This commit is contained in:
18
src/Units.extollo.ts
Normal file
18
src/Units.extollo.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
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";
|
||||
|
||||
export const Units = [
|
||||
Config,
|
||||
Files,
|
||||
CommandLine,
|
||||
Controllers,
|
||||
Middlewares,
|
||||
Database,
|
||||
Models,
|
||||
Internationalization,
|
||||
|
||||
Routing,
|
||||
HTTPServer,
|
||||
] as (typeof Unit)[]
|
||||
5
src/app/configs/app.config.ts
Normal file
5
src/app/configs/app.config.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { env } from '@extollo/lib'
|
||||
|
||||
export default {
|
||||
name: env('APP_NAME', 'Extollo'),
|
||||
}
|
||||
14
src/app/configs/database.config.ts
Normal file
14
src/app/configs/database.config.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { env } from "@extollo/lib";
|
||||
|
||||
export default {
|
||||
connections: {
|
||||
default: {
|
||||
user: env('DATABASE_USERNAME', 'extollo'),
|
||||
password: env('DATABASE_PASSWORD'),
|
||||
host: env('DATABASE_HOST', 'localhost'),
|
||||
port: env('DATABASE_PORT', 5432),
|
||||
database: env('DATABASE_NAME', 'extollo_1'),
|
||||
dialect: env('DATABASE_DIALECT', 'postgres'),
|
||||
},
|
||||
},
|
||||
}
|
||||
5
src/app/configs/lang/common.config.ts
Normal file
5
src/app/configs/lang/common.config.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { env } from "@extollo/lib"
|
||||
|
||||
export default {
|
||||
app_name: env('APP_NAME', 'Extollo'),
|
||||
}
|
||||
6
src/app/configs/lang/en_US.config.ts
Normal file
6
src/app/configs/lang/en_US.config.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import {env} from '@extollo/lib'
|
||||
|
||||
export default {
|
||||
welcome_to_extollo: 'Welcome to Extollo!',
|
||||
viewed_page_num_times: 'You have viewed this page :num: times.',
|
||||
}
|
||||
44
src/app/configs/server.config.ts
Normal file
44
src/app/configs/server.config.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import {env, basePath} from "@extollo/lib"
|
||||
import {ORMSession} from "@extollo/orm"
|
||||
import {LocalFilesystem, LocalFilesystemConfig} from "@extollo/util"
|
||||
|
||||
export default {
|
||||
debug: env('DEBUG_MODE', false),
|
||||
|
||||
session: {
|
||||
/* The implementation of @extollo/lib.Session that serves as the session backend. */
|
||||
driver: ORMSession,
|
||||
},
|
||||
|
||||
/*
|
||||
* Here, you can define various filesystem drivers that can be used in
|
||||
* your application to store/retrieve files.
|
||||
*
|
||||
* The key in the object is the 'name' of the filesystem as it will be
|
||||
* fetched in code. For example, if you have a `fubar: { ... }` item,
|
||||
* then you can retrieve that filesystem using the Files service like
|
||||
* so:
|
||||
*
|
||||
* files.getFilesystem('fubar') // => Filesystem { ... }
|
||||
*/
|
||||
filesystems: {
|
||||
default: {
|
||||
/* If true, this will serve as the default filesystem for modules in your application. */
|
||||
isDefault: true,
|
||||
|
||||
/* The implementation of @extollo/util.Filesystem that serves as the backend. */
|
||||
driver: LocalFilesystem,
|
||||
|
||||
/* The config required by the filesystem driver. */
|
||||
config: {
|
||||
baseDir: basePath('..', 'uploads').toLocal,
|
||||
} as LocalFilesystemConfig,
|
||||
}
|
||||
},
|
||||
|
||||
middleware: {
|
||||
global: {
|
||||
pre: ['LogRequest'],
|
||||
},
|
||||
},
|
||||
}
|
||||
21
src/app/http/controllers/main/Home.controller.ts
Normal file
21
src/app/http/controllers/main/Home.controller.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
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(),
|
||||
})
|
||||
}
|
||||
}
|
||||
12
src/app/http/middlewares/LogRequest.middleware.ts
Normal file
12
src/app/http/middlewares/LogRequest.middleware.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import {json, Logging, Middleware} from "@extollo/lib";
|
||||
import {Inject, Injectable} from "@extollo/di";
|
||||
|
||||
@Injectable()
|
||||
export class LogRequest extends Middleware {
|
||||
@Inject()
|
||||
protected readonly logging!: Logging
|
||||
|
||||
public async apply() {
|
||||
this.logging.info(`Incoming request: ${this.request.method} @ ${this.request.path}`)
|
||||
}
|
||||
}
|
||||
3
src/app/http/routes/app.routes.ts
Normal file
3
src/app/http/routes/app.routes.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import {Route} from "@extollo/lib"
|
||||
|
||||
Route.get('/', 'main:Home.welcome')
|
||||
6
src/app/models/User.model.ts
Normal file
6
src/app/models/User.model.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import {Model} from "@extollo/orm";
|
||||
|
||||
export class User extends Model<User> {
|
||||
protected static table = 'users';
|
||||
protected static key = 'user_id';
|
||||
}
|
||||
6
src/app/resources/views/welcome.pug
Normal file
6
src/app/resources/views/welcome.pug
Normal file
@@ -0,0 +1,6 @@
|
||||
html
|
||||
head
|
||||
title !{locale('app_name')}
|
||||
body
|
||||
h1 !{locale('welcome_to_extollo')}
|
||||
h2 !{locale('viewed_page_num_times', { interp: { num: app_visits } })}
|
||||
23
src/cli.ts
Normal file
23
src/cli.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import {Application} from "@extollo/lib";
|
||||
import {Units} from './Units.extollo';
|
||||
import {CommandLineApplication} from "@extollo/cli";
|
||||
|
||||
(async () => {
|
||||
/*
|
||||
* The Application
|
||||
* -----------------------------------------------------
|
||||
* The application instance is a global inversion of control container that
|
||||
* ties your entire application together. The app container manages services
|
||||
* and lifecycle.
|
||||
*/
|
||||
const app = Application.getApplication()
|
||||
app.forceStartupMessage = false
|
||||
|
||||
Units.reverse()
|
||||
CommandLineApplication.setReplacement(Units[0])
|
||||
Units[0] = CommandLineApplication
|
||||
Units.reverse()
|
||||
|
||||
app.scaffold(__dirname, Units)
|
||||
await app.run()
|
||||
})()
|
||||
15
src/index.ts
Normal file
15
src/index.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import {Application} from "@extollo/lib";
|
||||
import {Units} from './Units.extollo'
|
||||
|
||||
;(async () => {
|
||||
/*
|
||||
* The Application
|
||||
* -----------------------------------------------------
|
||||
* The application instance is a global inversion of control container that
|
||||
* ties your entire application together. The app container manages services
|
||||
* and lifecycle.
|
||||
*/
|
||||
const app = Application.getApplication()
|
||||
app.scaffold(__dirname, Units)
|
||||
await app.run()
|
||||
})()
|
||||
Reference in New Issue
Block a user