Serve all files and mime types.
This commit is contained in:
parent
03c744e9f1
commit
9805375421
2 changed files with 57 additions and 11 deletions
|
@ -1,3 +1,28 @@
|
||||||
|
;;
|
||||||
|
;; brminv.scm
|
||||||
|
;;
|
||||||
|
;; Main program of Brm Inventory - the server.
|
||||||
|
;;
|
||||||
|
;; ISC License
|
||||||
|
;;
|
||||||
|
;; Copyright 2023-2025 Brmlab, z.s.
|
||||||
|
;; Dominik Pantůček <dominik.pantucek@trustica.cz>
|
||||||
|
;;
|
||||||
|
;; Permission to use, copy, modify, and/or distribute this software
|
||||||
|
;; for any purpose with or without fee is hereby granted, provided
|
||||||
|
;; that the above copyright notice and this permission notice appear
|
||||||
|
;; in all copies.
|
||||||
|
;;
|
||||||
|
;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
||||||
|
;; WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
||||||
|
;; WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
||||||
|
;; AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
|
||||||
|
;; CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||||
|
;; OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
;; NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||||
|
;; CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
;;
|
||||||
|
|
||||||
(import frontend
|
(import frontend
|
||||||
command-line
|
command-line
|
||||||
texts
|
texts
|
||||||
|
@ -5,7 +30,8 @@
|
||||||
openssl
|
openssl
|
||||||
(chicken tcp)
|
(chicken tcp)
|
||||||
intarweb
|
intarweb
|
||||||
uri-common)
|
uri-common
|
||||||
|
(chicken string))
|
||||||
|
|
||||||
(define -port- (make-parameter #f))
|
(define -port- (make-parameter #f))
|
||||||
(define -certificate- (make-parameter #f))
|
(define -certificate- (make-parameter #f))
|
||||||
|
@ -55,17 +81,38 @@
|
||||||
(when (and (-user-) (-group-))
|
(when (and (-user-) (-group-))
|
||||||
(switch-user/group (-user-) (-group-)))
|
(switch-user/group (-user-) (-group-)))
|
||||||
|
|
||||||
|
(define (handle-request-by-path path)
|
||||||
|
(print (->string path-lst) (length path))
|
||||||
|
(define body
|
||||||
|
(cond ((equal? path-lst '(/ ""))
|
||||||
|
(print "index")
|
||||||
|
)
|
||||||
|
(else
|
||||||
|
"error"))))
|
||||||
|
|
||||||
|
(define (handle-api-calls)
|
||||||
|
#f)
|
||||||
|
|
||||||
(handle-not-found
|
(handle-not-found
|
||||||
(lambda (path)
|
(lambda (path)
|
||||||
(define path-lst (uri-path (request-uri (current-request))))
|
(define upath (string-intersperse (map ->string (cdr (uri-path (request-uri (current-request))))) "/"))
|
||||||
(print (car path-lst))
|
(cond ((equal? upath "")
|
||||||
(define body
|
(send-response #:body (frontend-lookup "index.html")))
|
||||||
(cond ((equal? (car path-lst) '/)
|
(else
|
||||||
(print "index")
|
(let ((maybe-asset (frontend-lookup upath #f)))
|
||||||
(frontend-lookup "index.html" "index not found"))
|
(cond (maybe-asset
|
||||||
(else
|
(send-response
|
||||||
"error")))
|
#:headers (let ((ext (car (reverse (string-split upath ".")))))
|
||||||
(send-response #:body body)))
|
(cond ((equal? ext "css")
|
||||||
|
'((content-type #("text/css" ()))))
|
||||||
|
((equal? ext "js")
|
||||||
|
'((content-type #("text/javascript" ()))))
|
||||||
|
(else
|
||||||
|
'())))
|
||||||
|
#:body maybe-asset))
|
||||||
|
(else
|
||||||
|
(when (not (handle-api-calls))
|
||||||
|
(send-response #:body (frontend-lookup "index.html"))))))))))
|
||||||
|
|
||||||
(accept-loop listener
|
(accept-loop listener
|
||||||
(if ssl?
|
(if ssl?
|
||||||
|
|
|
@ -4,5 +4,4 @@ import react from '@vitejs/plugin-react'
|
||||||
// https://vite.dev/config/
|
// https://vite.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
base: '/brm/inv/dist',
|
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue