Skip to content

Commit 3bae489

Browse files
committed
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.
1 parent f2e0ab5 commit 3bae489

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

examples/vweb/vweb_assets/vweb_assets.v

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module main
22

3+
import os
34
import vweb
45
// import vweb.assets
56
import time
@@ -16,6 +17,7 @@ fn main() {
1617
mut app := &App{}
1718
app.serve_static('/favicon.ico', 'favicon.ico')
1819
// Automatically make available known static mime types found in given directory.
20+
os.chdir(os.dir(os.executable())) ?
1921
app.handle_static('assets', true)
2022
vweb.run(app, port)
2123
}

vlib/vweb/vweb.v

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,14 @@ fn (mut ctx Context) scan_static_directory(directory_path string, mount_path str
628628
}
629629
}
630630

631-
// Handles a directory static
631+
// handle_static is used to mark a folder (relative to the current working folder)
632+
// as one that contains only static resources (css files, images etc).
632633
// If `root` is set the mount path for the dir will be in '/'
634+
// Usage:
635+
// ```v
636+
// os.chdir( os.executable() ) ?
637+
// app.handle_static('assets', true)
638+
// ```
633639
pub fn (mut ctx Context) handle_static(directory_path string, root bool) bool {
634640
if ctx.done || !os.exists(directory_path) {
635641
return false

0 commit comments

Comments
 (0)