2020-03-07 14:16:03 +01:00
|
|
|
module main
|
|
|
|
|
2022-03-21 18:05:18 +01:00
|
|
|
import os
|
2020-04-26 13:49:31 +02:00
|
|
|
import vweb
|
2021-04-20 16:16:35 +02:00
|
|
|
// import vweb.assets
|
2020-04-26 13:49:31 +02:00
|
|
|
import time
|
2020-03-07 14:16:03 +01:00
|
|
|
|
|
|
|
const (
|
|
|
|
port = 8081
|
|
|
|
)
|
|
|
|
|
2020-06-07 10:02:35 +02:00
|
|
|
struct App {
|
2020-12-31 17:22:47 +01:00
|
|
|
vweb.Context
|
2020-03-07 14:16:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2021-08-01 20:46:30 +02:00
|
|
|
mut app := &App{}
|
2021-05-22 06:02:21 +02:00
|
|
|
app.serve_static('/favicon.ico', 'favicon.ico')
|
2020-03-07 14:16:03 +01:00
|
|
|
// Automatically make available known static mime types found in given directory.
|
2022-03-21 18:05:18 +01:00
|
|
|
os.chdir(os.dir(os.executable())) ?
|
2021-08-01 20:46:30 +02:00
|
|
|
app.handle_static('assets', true)
|
|
|
|
vweb.run(app, port)
|
2020-03-07 14:16:03 +01:00
|
|
|
}
|
|
|
|
|
2021-01-07 20:46:23 +01:00
|
|
|
pub fn (mut app App) index() vweb.Result {
|
2020-03-07 14:16:03 +01:00
|
|
|
// We can dynamically specify which assets are to be used in template.
|
2021-01-30 14:20:13 +01:00
|
|
|
// mut am := assets.new_manager()
|
|
|
|
// am.add_css('assets/index.css')
|
|
|
|
// css := am.include_css(false)
|
2020-03-07 14:16:03 +01: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 20:46:23 +01:00
|
|
|
return $vweb.html()
|
2020-03-07 14:16:03 +01:00
|
|
|
}
|
|
|
|
|
2020-12-31 17:22:47 +01:00
|
|
|
fn (mut app App) text() vweb.Result {
|
2021-01-01 14:36:07 +01:00
|
|
|
return app.Context.text('Hello, world from vweb!')
|
2020-03-07 14:16:03 +01:00
|
|
|
}
|
|
|
|
|
2020-12-31 17:22:47 +01:00
|
|
|
fn (mut app App) time() vweb.Result {
|
2021-01-01 14:36:07 +01:00
|
|
|
return app.Context.text(time.now().format())
|
2020-03-07 14:16:03 +01:00
|
|
|
}
|