2020-03-07 16:16:03 +03:00
|
|
|
module main
|
|
|
|
|
2020-04-26 14:49:31 +03:00
|
|
|
import vweb
|
2021-04-20 17:16:35 +03:00
|
|
|
// import vweb.assets
|
2020-04-26 14:49:31 +03:00
|
|
|
import time
|
2020-03-07 16:16:03 +03:00
|
|
|
|
|
|
|
const (
|
|
|
|
port = 8081
|
|
|
|
)
|
|
|
|
|
2020-06-07 11:02:35 +03:00
|
|
|
struct App {
|
2020-12-31 19:22:47 +03:00
|
|
|
vweb.Context
|
2020-03-07 16:16:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
vweb.run<App>(port)
|
|
|
|
}
|
|
|
|
|
2020-06-10 13:05:35 +03:00
|
|
|
pub fn (mut app App) init_once() {
|
2020-03-07 16:16:03 +03:00
|
|
|
// Arbitary mime type.
|
2020-12-31 19:22:47 +03:00
|
|
|
app.serve_static('/favicon.ico', 'favicon.ico', 'img/x-icon')
|
2020-03-07 16:16:03 +03:00
|
|
|
// Automatically make available known static mime types found in given directory.
|
2021-01-30 16:20:13 +03:00
|
|
|
// app.handle_static('assets')
|
2020-03-07 16:16:03 +03:00
|
|
|
// This would make available all known static mime types from current
|
|
|
|
// directory and below.
|
2021-02-21 21:01:29 +03:00
|
|
|
app.handle_static('.', false)
|
2020-03-07 16:16:03 +03:00
|
|
|
}
|
|
|
|
|
2020-09-08 01:38:24 +03:00
|
|
|
pub fn (mut app App) init() {
|
|
|
|
}
|
2020-03-07 16:16:03 +03:00
|
|
|
|
2021-01-07 22:46:23 +03:00
|
|
|
pub fn (mut app App) index() vweb.Result {
|
2020-03-07 16:16:03 +03:00
|
|
|
// We can dynamically specify which assets are to be used in template.
|
2021-01-30 16:20:13 +03:00
|
|
|
// mut am := assets.new_manager()
|
|
|
|
// am.add_css('assets/index.css')
|
|
|
|
// css := am.include_css(false)
|
2020-03-07 16:16:03 +03:00
|
|
|
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.'
|
2021-01-07 22:46:23 +03:00
|
|
|
return $vweb.html()
|
2020-03-07 16:16:03 +03:00
|
|
|
}
|
|
|
|
|
2020-12-31 19:22:47 +03:00
|
|
|
fn (mut app App) text() vweb.Result {
|
2021-01-01 16:36:07 +03:00
|
|
|
return app.Context.text('Hello, world from vweb!')
|
2020-03-07 16:16:03 +03:00
|
|
|
}
|
|
|
|
|
2020-12-31 19:22:47 +03:00
|
|
|
fn (mut app App) time() vweb.Result {
|
2021-01-01 16:36:07 +03:00
|
|
|
return app.Context.text(time.now().format())
|
2020-03-07 16:16:03 +03:00
|
|
|
}
|