vweb: fix serving static files
parent
170282b2af
commit
ed6ad728d9
|
@ -123,7 +123,7 @@ pub:
|
|||
typ int
|
||||
}
|
||||
|
||||
pub enum AttributeKind {
|
||||
enum AttributeKind {
|
||||
plain // [name]
|
||||
string // ['name']
|
||||
number // [123]
|
||||
|
|
|
@ -7,6 +7,7 @@ const (
|
|||
tcp_default_write_timeout = 30 * time.second
|
||||
)
|
||||
|
||||
[heap]
|
||||
pub struct TcpConn {
|
||||
pub mut:
|
||||
sock TcpSocket
|
||||
|
|
|
@ -126,6 +126,12 @@ fn test_orm_sqlite() {
|
|||
assert users3[0].age == 29
|
||||
assert users3[1].age == 31
|
||||
//
|
||||
missing_user := sql db {
|
||||
select from User where id == 8777
|
||||
}
|
||||
println('missing_user:')
|
||||
println(missing_user) // zero struct
|
||||
//
|
||||
new_user := User{
|
||||
name: 'New user'
|
||||
age: 30
|
||||
|
|
|
@ -21,6 +21,7 @@ fn test_sqlite() {
|
|||
code = db.exec_none('vacuum')
|
||||
assert code == 101
|
||||
user := db.exec_one('select * from users where id = 3') or { panic(err) }
|
||||
println(user)
|
||||
assert user.vals.len == 2
|
||||
db.close() or { panic(err) }
|
||||
assert !db.is_open
|
||||
|
|
|
@ -3098,6 +3098,11 @@ pub fn (mut c Checker) enum_decl(decl ast.EnumDecl) {
|
|||
if decl.fields.len == 0 {
|
||||
c.error('enum cannot be empty', decl.pos)
|
||||
}
|
||||
/*
|
||||
if decl.is_pub && c.mod == 'builtin' {
|
||||
c.error('`builtin` module cannot have enums', decl.pos)
|
||||
}
|
||||
*/
|
||||
for i, field in decl.fields {
|
||||
if !c.pref.experimental && util.contains_capital(field.name) {
|
||||
// TODO C2V uses hundreds of enums with capitals, remove -experimental check once it's handled
|
||||
|
|
|
@ -322,6 +322,7 @@ pub fn run<T>(global_app &T, port int) {
|
|||
} $else {
|
||||
// println('vweb no db')
|
||||
}
|
||||
request_app.Context = global_app.Context // copy the context ref that contains static files map etc
|
||||
// request_app.Context = Context{
|
||||
// conn: 0
|
||||
//}
|
||||
|
@ -351,7 +352,7 @@ fn handle_conn<T>(mut conn net.TcpConn, mut app T) {
|
|||
}
|
||||
app.Context = Context{
|
||||
req: req
|
||||
conn: unsafe { conn }
|
||||
conn: conn
|
||||
form: map[string]string{}
|
||||
static_files: app.static_files
|
||||
static_mime_types: app.static_mime_types
|
||||
|
@ -385,7 +386,7 @@ fn handle_conn<T>(mut conn net.TcpConn, mut app T) {
|
|||
eprintln('error parsing path: $err')
|
||||
return
|
||||
}
|
||||
if serve_static<T>(mut app, url) {
|
||||
if serve_if_static<T>(mut app, url) {
|
||||
// successfully served a static file
|
||||
return
|
||||
}
|
||||
|
@ -528,7 +529,8 @@ fn parse_attrs(name string, attrs []string) ?([]http.Method, string) {
|
|||
|
||||
// check if request is for a static file and serves it
|
||||
// returns true if we served a static file, false otherwise
|
||||
fn serve_static<T>(mut app T, url urllib.URL) bool {
|
||||
[manualfree]
|
||||
fn serve_if_static<T>(mut app T, url urllib.URL) bool {
|
||||
// TODO: handle url parameters properly - for now, ignore them
|
||||
static_file := app.static_files[url.path]
|
||||
mime_type := app.static_mime_types[url.path]
|
||||
|
|
Loading…
Reference in New Issue