aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/examples/vweb/vweb_assets/vweb_assets.v
diff options
context:
space:
mode:
Diffstat (limited to 'v_windows/v/examples/vweb/vweb_assets/vweb_assets.v')
-rw-r--r--v_windows/v/examples/vweb/vweb_assets/vweb_assets.v40
1 files changed, 40 insertions, 0 deletions
diff --git a/v_windows/v/examples/vweb/vweb_assets/vweb_assets.v b/v_windows/v/examples/vweb/vweb_assets/vweb_assets.v
new file mode 100644
index 0000000..058f459
--- /dev/null
+++ b/v_windows/v/examples/vweb/vweb_assets/vweb_assets.v
@@ -0,0 +1,40 @@
+module main
+
+import vweb
+// import vweb.assets
+import time
+
+const (
+ port = 8081
+)
+
+struct App {
+ vweb.Context
+}
+
+fn main() {
+ mut app := &App{}
+ app.serve_static('/favicon.ico', 'favicon.ico')
+ // Automatically make available known static mime types found in given directory.
+ app.handle_static('assets', true)
+ vweb.run(app, port)
+}
+
+pub fn (mut app App) index() vweb.Result {
+ // We can dynamically specify which assets are to be used in template.
+ // mut am := assets.new_manager()
+ // am.add_css('assets/index.css')
+ // css := am.include_css(false)
+ title := 'VWeb Assets Example'
+ subtitle := 'VWeb can serve static assets too!'
+ message := 'It also has an Assets Manager that allows dynamically specifying which CSS and JS files to be used.'
+ return $vweb.html()
+}
+
+fn (mut app App) text() vweb.Result {
+ return app.Context.text('Hello, world from vweb!')
+}
+
+fn (mut app App) time() vweb.Result {
+ return app.Context.text(time.now().format())
+}