examples: make the vweb_assets.v example more robust (always change work folder to the folder of the executable). Document the vweb.Context.handle_static behaviour.
parent
f2e0ab5912
commit
3bae489e35
|
@ -1,5 +1,6 @@
|
||||||
module main
|
module main
|
||||||
|
|
||||||
|
import os
|
||||||
import vweb
|
import vweb
|
||||||
// import vweb.assets
|
// import vweb.assets
|
||||||
import time
|
import time
|
||||||
|
@ -16,6 +17,7 @@ fn main() {
|
||||||
mut app := &App{}
|
mut app := &App{}
|
||||||
app.serve_static('/favicon.ico', 'favicon.ico')
|
app.serve_static('/favicon.ico', 'favicon.ico')
|
||||||
// Automatically make available known static mime types found in given directory.
|
// Automatically make available known static mime types found in given directory.
|
||||||
|
os.chdir(os.dir(os.executable())) ?
|
||||||
app.handle_static('assets', true)
|
app.handle_static('assets', true)
|
||||||
vweb.run(app, port)
|
vweb.run(app, port)
|
||||||
}
|
}
|
||||||
|
|
|
@ -628,8 +628,14 @@ fn (mut ctx Context) scan_static_directory(directory_path string, mount_path str
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handles a directory static
|
// handle_static is used to mark a folder (relative to the current working folder)
|
||||||
|
// as one that contains only static resources (css files, images etc).
|
||||||
// If `root` is set the mount path for the dir will be in '/'
|
// If `root` is set the mount path for the dir will be in '/'
|
||||||
|
// Usage:
|
||||||
|
// ```v
|
||||||
|
// os.chdir( os.executable() ) ?
|
||||||
|
// app.handle_static('assets', true)
|
||||||
|
// ```
|
||||||
pub fn (mut ctx Context) handle_static(directory_path string, root bool) bool {
|
pub fn (mut ctx Context) handle_static(directory_path string, root bool) bool {
|
||||||
if ctx.done || !os.exists(directory_path) {
|
if ctx.done || !os.exists(directory_path) {
|
||||||
return false
|
return false
|
||||||
|
|
Loading…
Reference in New Issue