hopefully fixed pointer deref / invalid mem access issue
This commit is contained in:
@@ -3,6 +3,7 @@ module main
|
||||
import os
|
||||
import veb
|
||||
import util
|
||||
import thomaspeissl.dotenv
|
||||
|
||||
//
|
||||
|
||||
@@ -24,13 +25,15 @@ pub struct App {
|
||||
veb.Controller
|
||||
veb.StaticHandler
|
||||
veb.Middleware[Context]
|
||||
pub mut:
|
||||
embed util.Embedded
|
||||
pub:
|
||||
cfg util.Config
|
||||
cfg &util.Config
|
||||
embed util.Embedded
|
||||
}
|
||||
|
||||
pub struct Auth {}
|
||||
pub struct Auth {
|
||||
pub:
|
||||
app &App
|
||||
}
|
||||
|
||||
// endpoints
|
||||
|
||||
@@ -80,7 +83,7 @@ pub fn (auth &Auth) register(mut ctx Context) veb.Result {
|
||||
// utility
|
||||
|
||||
fn (mut ctx Context) error_page(code int, short string, long string) string {
|
||||
style := ctx.embed.error_css
|
||||
style := ctx.embed.error_css.clone()
|
||||
return $tmpl('template/error.html')
|
||||
}
|
||||
|
||||
@@ -96,7 +99,10 @@ pub fn (mut ctx Context) not_found() veb.Result {
|
||||
|
||||
// --
|
||||
|
||||
fn populate() &util.Config {
|
||||
fn populate() (&util.Config, &util.Embedded) {
|
||||
dotenv.load()
|
||||
dotenv.require('CDN_DB_HOST', 'CDN_DB_PORT')
|
||||
|
||||
def_root := $d('root', '.')
|
||||
def_port := int($d('port', 6767))
|
||||
|
||||
@@ -107,6 +113,8 @@ fn populate() &util.Config {
|
||||
root: if os.getenv('CDN_ROOT') != '' { os.getenv('CDN_ROOT').str() } else { def_root }
|
||||
port: if os.getenv('CDN_PORT') != '' { os.getenv('CDN_PORT').int() } else { def_port }
|
||||
database: &util.Database{
|
||||
host: os.getenv('CDN_DB_HOST').str()
|
||||
port: os.getenv('CDN_DB_PORT').int()
|
||||
username: if os.getenv('CDN_DB_USERNAME') != '' {
|
||||
os.getenv('CDN_DB_USERNAME').str()
|
||||
} else {
|
||||
@@ -118,17 +126,20 @@ fn populate() &util.Config {
|
||||
def_pass
|
||||
}
|
||||
}
|
||||
}, &util.Embedded{
|
||||
style_css: $embed_file('assets/style/style.css', .zlib).to_string()
|
||||
error_css: $embed_file('assets/style/error.css', .zlib).to_string()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
cfg, mut embed := populate()
|
||||
mut app := &App{
|
||||
cfg: populate()
|
||||
cfg: cfg
|
||||
embed: embed
|
||||
}
|
||||
mut auth := &Auth{}
|
||||
app.embed = &util.Embedded{
|
||||
style_css: $embed_file('assets/style/style.css', .zlib).to_string()
|
||||
error_css: $embed_file('assets/style/error.css', .zlib).to_string()
|
||||
mut auth := &Auth{
|
||||
app: &app
|
||||
}
|
||||
|
||||
app.register_controller[Auth, Context]('/auth', mut auth)!
|
||||
@@ -137,8 +148,8 @@ fn main() {
|
||||
app.use(veb.encode_auto[Context]())
|
||||
|
||||
app.use(veb.MiddlewareOptions[Context]{
|
||||
handler: fn [app] (mut ctx Context) bool {
|
||||
ctx.embed = &app.embed
|
||||
handler: fn [mut embed] (mut ctx Context) bool {
|
||||
ctx.embed = embed
|
||||
return true
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user