1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vweb: return 404 on file not found (#18219)

This commit is contained in:
sandbankdisperser 2023-05-21 15:23:43 +02:00 committed by GitHub
parent e4c769d072
commit f833188234
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -256,6 +256,10 @@ pub fn (mut ctx Context) json_pretty[T](j T) Result {
// TODO - test // TODO - test
// Response HTTP_OK with file as payload // Response HTTP_OK with file as payload
pub fn (mut ctx Context) file(f_path string) Result { pub fn (mut ctx Context) file(f_path string) Result {
if !os.exists(f_path) {
eprintln('[vweb] file ${f_path} does not exist')
return ctx.not_found()
}
ext := os.file_ext(f_path) ext := os.file_ext(f_path)
data := os.read_file(f_path) or { data := os.read_file(f_path) or {
eprint(err.msg()) eprint(err.msg())