mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
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.
This commit is contained in:
parent
f2e0ab5912
commit
3bae489e35
@ -1,5 +1,6 @@
|
||||
module main
|
||||
|
||||
import os
|
||||
import vweb
|
||||
// import vweb.assets
|
||||
import time
|
||||
@ -16,6 +17,7 @@ fn main() {
|
||||
mut app := &App{}
|
||||
app.serve_static('/favicon.ico', 'favicon.ico')
|
||||
// Automatically make available known static mime types found in given directory.
|
||||
os.chdir(os.dir(os.executable())) ?
|
||||
app.handle_static('assets', true)
|
||||
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 '/'
|
||||
// Usage:
|
||||
// ```v
|
||||
// os.chdir( os.executable() ) ?
|
||||
// app.handle_static('assets', true)
|
||||
// ```
|
||||
pub fn (mut ctx Context) handle_static(directory_path string, root bool) bool {
|
||||
if ctx.done || !os.exists(directory_path) {
|
||||
return false
|
||||
|
Loading…
Reference in New Issue
Block a user