Introduce async local storage for request access, more view globals, and improved welcome view
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
b5eb407b55
commit
463076d182
@ -0,0 +1,32 @@
|
||||
import { AsyncLocalStorage } from 'async_hooks'
|
||||
import {Request} from './lifecycle/Request'
|
||||
import {Singleton} from '../di'
|
||||
import {ErrorWithContext} from '../util'
|
||||
|
||||
export class InvalidOutOfRequestAccessError extends ErrorWithContext {
|
||||
constructor() {
|
||||
super(`Attempted to access request via local storage outside of async lifecycle!`)
|
||||
}
|
||||
}
|
||||
|
||||
@Singleton()
|
||||
export class RequestLocalStorage {
|
||||
protected readonly store: AsyncLocalStorage<Request> = new AsyncLocalStorage<Request>()
|
||||
|
||||
get(): Request {
|
||||
const req = this.store.getStore()
|
||||
if ( !req ) {
|
||||
throw new InvalidOutOfRequestAccessError()
|
||||
}
|
||||
|
||||
return req
|
||||
}
|
||||
|
||||
has(): boolean {
|
||||
return Boolean(this.store.getStore())
|
||||
}
|
||||
|
||||
run<T>(req: Request, closure: () => T): T {
|
||||
return this.store.run(req, closure)
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 2.2 KiB |
@ -0,0 +1,17 @@
|
||||
doctype html
|
||||
html
|
||||
head
|
||||
meta(charset='utf-8')
|
||||
meta(name='viewport' content='width=device-width, initial-scale=1')
|
||||
block head
|
||||
block styles
|
||||
block prescripts
|
||||
script.
|
||||
if (typeof $ !== 'function') {
|
||||
window.$ = (...args) => document.querySelector(...args)
|
||||
}
|
||||
script(src=vendor('@extollo/ui', 'extollo-ui.dist.js') type='module')
|
||||
body
|
||||
ex-page
|
||||
block content
|
||||
block scripts
|
@ -0,0 +1,18 @@
|
||||
extends base
|
||||
|
||||
block content
|
||||
ex-nav
|
||||
img(src=vendor('@extollo/lib', 'extollo.svg') slot='branding' width=115 style="margin-right: 30px" alt=config('app.name'))
|
||||
ex-nav-item(title='Home' name='home' href=route('/'))
|
||||
ex-nav-item(title='Documentation' name='documentation' href='https://extollo.garrettmills.dev')
|
||||
|
||||
if hasRoute('@auth.login')
|
||||
if user()
|
||||
ex-nav-item(title='Welcome, ' + user().getDisplay() name='user' href=named('@auth.logout') right)
|
||||
else
|
||||
ex-nav-item(title='Login' name='login' href=named('@auth.login') right)
|
||||
|
||||
h1 Welcome to #{config('app.name')}
|
||||
p You have successfully created your new application, #{config('app.name')}, based on the Extollo framework.
|
||||
p For more information on Extollo, visit the framework documentation using the link above.
|
||||
blockquote You can customize this view by modifying <code>src/app/resources/views/welcome.pug</code>.
|
Loading…
Reference in new issue