Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadMD1383 committed Sep 11, 2022
0 parents commit 0cc685a
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.v]
indent_style = tab
indent_size = 4
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.v linguist-language=V text=auto eol=lf
*.vv linguist-language=V text=auto eol=lf
*.vsh linguist-language=V text=auto eol=lf
**/v.mod linguist-language=V text=auto eol=lf
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Binaries for programs and plugins
main
verve
*.exe
*.exe~
*.so
*.dylib
*.dll
vls.log
7 changes: 7 additions & 0 deletions v.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Module {
name: 'verve'
description: 'simple, fast and powerful static file server with no dependencies written in V'
version: '1.0.0'
license: 'MIT'
dependencies: []
}
50 changes: 50 additions & 0 deletions verve.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module main

import os
import vweb
import flag

struct Server {
vweb.Context
}

fn main() {
mut fp := flag.new_flag_parser(os.args)
fp.application("verve")
fp.version("1.0.0")
fp.limit_free_args(0, 0)?
fp.description("simple, fast and powerful static file server with no dependencies written in V")
fp.skip_executable()

help := fp.bool("help", `h`, false, "show this help message")
port := fp.int("port", `p`, 7777, "the port to be used [=7777]")
dir := fp.string("dir", `d`, ".", "the dir to serve its content [='.']")

fp.finalize() or {
eprintln(err)
println(fp.usage())
return
}

if help {
println(fp.usage())
return
}

mut server := &Server{}
server.mount_static_folder_at(
if os.is_abs_path(dir) { dir } else { os.resource_abs_path(dir) },
"/"
)

vweb.run(server, port)
}

["/"]
fn (mut server Server) index() vweb.Result {
if "/index.html" in server.static_files.keys() {
return server.file(server.static_files["/index.html"])
}

return server.not_found()
}

0 comments on commit 0cc685a

Please sign in to comment.