Initial commit
This commit is contained in:
46
src/Units.extollo.ts
Normal file
46
src/Units.extollo.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import {
|
||||
Config,
|
||||
Controllers,
|
||||
HTTPServer,
|
||||
Files,
|
||||
Middlewares,
|
||||
Routing,
|
||||
Unit,
|
||||
Database,
|
||||
Models,
|
||||
CommandLine,
|
||||
Internationalization,
|
||||
Authentication,
|
||||
Discovery,
|
||||
ValidationUnit,
|
||||
Migrations,
|
||||
Queueables,
|
||||
Redis,
|
||||
Bus,
|
||||
} from '@extollo/lib'
|
||||
import {AppUnit} from './app/AppUnit'
|
||||
|
||||
Error.stackTraceLimit = 500
|
||||
|
||||
export const Units = [
|
||||
Config,
|
||||
Redis,
|
||||
Queueables,
|
||||
Bus,
|
||||
ValidationUnit,
|
||||
Files,
|
||||
CommandLine,
|
||||
Controllers,
|
||||
Middlewares,
|
||||
Database,
|
||||
Models,
|
||||
Migrations,
|
||||
Internationalization,
|
||||
Authentication,
|
||||
|
||||
AppUnit,
|
||||
|
||||
Routing,
|
||||
Discovery,
|
||||
HTTPServer,
|
||||
] as (typeof Unit)[]
|
||||
9
src/app/AppUnit.ts
Normal file
9
src/app/AppUnit.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import {ORMUser, Singleton, Unit} from '@extollo/lib'
|
||||
import {User} from './models/User.model'
|
||||
|
||||
@Singleton()
|
||||
export class AppUnit extends Unit {
|
||||
async up(): Promise<void> {
|
||||
this.container().registerStaticOverride(ORMUser, User)
|
||||
}
|
||||
}
|
||||
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'),
|
||||
}
|
||||
21
src/app/configs/auth.config.ts
Normal file
21
src/app/configs/auth.config.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import {AuthenticationConfig, CoreIDLoginProvider, OAuth2LoginProviderConfig, ORMUserRepository, env} from '@extollo/lib'
|
||||
|
||||
const authConfig: AuthenticationConfig = {
|
||||
storage: ORMUserRepository,
|
||||
providers: {
|
||||
coreid: {
|
||||
driver: CoreIDLoginProvider,
|
||||
config: {
|
||||
default: true,
|
||||
displayName: 'Starship CoreID',
|
||||
clientId: env('COREID_CLIENT_ID'),
|
||||
clientSecret: env('COREID_CLIENT_SECRET'),
|
||||
loginUrl: env('COREID_BASE', '') + '/auth/service/oauth2/authorize?client_id=%c&redirect_uri=%r',
|
||||
tokenUrl: env('COREID_BASE', '') + '/auth/service/oauth2/redeem',
|
||||
userUrl: env('COREID_BASE', '') + '/api/v1/auth/users/me',
|
||||
} as OAuth2LoginProviderConfig,
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
export default authConfig
|
||||
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'),
|
||||
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.',
|
||||
}
|
||||
24
src/app/configs/oauth2.config.ts
Normal file
24
src/app/configs/oauth2.config.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import {OAuth2Client, OAuth2Scope, env, /*uuid4*/} from '@extollo/lib'
|
||||
|
||||
export default {
|
||||
secret: env('OAUTH2_SECRET'),
|
||||
scopes: {
|
||||
'user-info': {
|
||||
id: 'user-info',
|
||||
name: 'user-info',
|
||||
description: 'access basic information about your account',
|
||||
},
|
||||
} as {[key: string]: OAuth2Scope},
|
||||
clients: {
|
||||
// 'test-1': {
|
||||
// id: 'test-1',
|
||||
// display: 'Test 1',
|
||||
// secret: env('TEST_CLIENT_SECRET', uuid4()),
|
||||
// allowedFlows: ['code'],
|
||||
// allowedScopeIds: ['user-info'],
|
||||
// allowedRedirectUris: [
|
||||
// 'http://localhost:1234/callback',
|
||||
// ],
|
||||
// },
|
||||
} as {[key: string]: OAuth2Client},
|
||||
}
|
||||
66
src/app/configs/server.config.ts
Normal file
66
src/app/configs/server.config.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import {
|
||||
env,
|
||||
basePath,
|
||||
ORMSession,
|
||||
LocalFilesystem,
|
||||
LocalFilesystemConfig,
|
||||
RedisCache,
|
||||
CacheQueue,
|
||||
BusConnectorConfig, QueueConfig, SyncQueue
|
||||
} from "@extollo/lib"
|
||||
import {LogRequest} from "../http/middlewares/LogRequest.middleware";
|
||||
|
||||
export default {
|
||||
debug: env('DEBUG_MODE', false),
|
||||
|
||||
session: {
|
||||
/* The implementation of @extollo/lib.Session that serves as the session backend. */
|
||||
driver: ORMSession,
|
||||
},
|
||||
|
||||
bus: {
|
||||
connectors: [
|
||||
{type: 'redis'},
|
||||
] as BusConnectorConfig[],
|
||||
},
|
||||
|
||||
queue: {
|
||||
driver: CacheQueue,
|
||||
} as QueueConfig,
|
||||
|
||||
cache: {
|
||||
driver: RedisCache,
|
||||
},
|
||||
|
||||
/*
|
||||
* 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/lib.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],
|
||||
},
|
||||
},
|
||||
}
|
||||
26
src/app/http/controllers/main/Home.controller.ts
Normal file
26
src/app/http/controllers/main/Home.controller.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import {Controller, view, Session, Inject, Injectable, Locale, Validator} from '@extollo/lib'
|
||||
import {UserLogin} from "../../../types/UserLogin";
|
||||
|
||||
@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)
|
||||
|
||||
const valid = new Promise<UserLogin>(() => {})
|
||||
|
||||
return view('@extollo:welcome', {
|
||||
app_visits: this.session.get('app_visits'),
|
||||
locale: this.locale.helper(),
|
||||
})
|
||||
}
|
||||
|
||||
public test() {
|
||||
return new Validator<UserLogin>()
|
||||
}
|
||||
}
|
||||
11
src/app/http/middlewares/LogRequest.middleware.ts
Normal file
11
src/app/http/middlewares/LogRequest.middleware.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import {Inject, Injectable, Logging, Middleware} from '@extollo/lib'
|
||||
|
||||
@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}`)
|
||||
}
|
||||
}
|
||||
13
src/app/http/routes/app.routes.ts
Normal file
13
src/app/http/routes/app.routes.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import {Route, SessionAuthMiddleware, AuthRequiredMiddleware} from '@extollo/lib'
|
||||
import {Home} from '../controllers/main/Home.controller'
|
||||
|
||||
Route.group('/', () => {
|
||||
Route.get('/')
|
||||
.calls<Home>(Home, home => home.welcome)
|
||||
})
|
||||
|
||||
Route.group('', () => {
|
||||
Route.get('/dash')
|
||||
.pre(AuthRequiredMiddleware)
|
||||
.calls<Home>(Home, home => home.welcome)
|
||||
}).pre(SessionAuthMiddleware)
|
||||
15
src/app/jobs/LogMessage.job.ts
Normal file
15
src/app/jobs/LogMessage.job.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import {Inject, Injectable, Logging, BaseJob} from '@extollo/lib'
|
||||
|
||||
@Injectable()
|
||||
export default class LogMessage extends BaseJob {
|
||||
@Inject()
|
||||
protected readonly logging!: Logging
|
||||
|
||||
async execute(): Promise<void> {
|
||||
this.logging.info('Executing LogMessage...')
|
||||
await new Promise<void>(res => {
|
||||
setTimeout(() => res(), 3000)
|
||||
})
|
||||
this.logging.success('The LogMessage job has executed!')
|
||||
}
|
||||
}
|
||||
5
src/app/models/User.model.ts
Normal file
5
src/app/models/User.model.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import {ORMUser} from '@extollo/lib'
|
||||
|
||||
export class User extends ORMUser {
|
||||
|
||||
}
|
||||
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 } })}
|
||||
14
src/app/types/UserLogin.ts
Normal file
14
src/app/types/UserLogin.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
export interface UserLogin {
|
||||
/**
|
||||
* @minLength 1
|
||||
* @maxLength 100
|
||||
*/
|
||||
username: string,
|
||||
|
||||
/**
|
||||
* @minLength 1
|
||||
* @maxLength 100
|
||||
*/
|
||||
password: string,
|
||||
}
|
||||
43
src/bootstrap.ts
Normal file
43
src/bootstrap.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import {Application, CommandLineApplication} from '@extollo/lib'
|
||||
import {Units} from './Units.extollo'
|
||||
|
||||
/*
|
||||
* Helper functions to bootstrap the Application instance for different uses.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get the base application with no final-target unit.
|
||||
*/
|
||||
export function base(): Application {
|
||||
const app = Application.getApplication()
|
||||
app.scaffold(__dirname, Units.slice(0, -1))
|
||||
return app
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the application with the final unit replaced with the CommandLineApplication
|
||||
* for use on the CLI.
|
||||
*/
|
||||
export function cli(): Application {
|
||||
const app = Application.getApplication()
|
||||
app.forceStartupMessage = false
|
||||
|
||||
const units = [...Units]
|
||||
|
||||
units.reverse()
|
||||
CommandLineApplication.setReplacement(units[0])
|
||||
units[0] = CommandLineApplication
|
||||
units.reverse()
|
||||
|
||||
app.scaffold(__dirname, units)
|
||||
return app
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the application as it should be run normally.
|
||||
*/
|
||||
export function app(): Application {
|
||||
const app = Application.getApplication()
|
||||
app.scaffold(__dirname, Units)
|
||||
return app
|
||||
}
|
||||
15
src/cli.ts
Normal file
15
src/cli.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env -S node --experimental-repl-await
|
||||
import {globalRegistry} from '@extollo/lib'
|
||||
import {cli} from './bootstrap'
|
||||
|
||||
globalRegistry.run(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 = cli()
|
||||
await app.run()
|
||||
})
|
||||
13
src/index.ts
Normal file
13
src/index.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import {globalRegistry} from '@extollo/lib'
|
||||
import {app} from './bootstrap'
|
||||
|
||||
globalRegistry.run(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.
|
||||
*/
|
||||
await app().run()
|
||||
})
|
||||
Reference in New Issue
Block a user