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
|
||||
command-line
|
||||
texts
|
||||
|
@ -5,7 +30,8 @@
|
|||
openssl
|
||||
(chicken tcp)
|
||||
intarweb
|
||||
uri-common)
|
||||
uri-common
|
||||
(chicken string))
|
||||
|
||||
(define -port- (make-parameter #f))
|
||||
(define -certificate- (make-parameter #f))
|
||||
|
@ -55,17 +81,38 @@
|
|||
(when (and (-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
|
||||
(lambda (path)
|
||||
(define path-lst (uri-path (request-uri (current-request))))
|
||||
(print (car path-lst))
|
||||
(define body
|
||||
(cond ((equal? (car path-lst) '/)
|
||||
(print "index")
|
||||
(frontend-lookup "index.html" "index not found"))
|
||||
(else
|
||||
"error")))
|
||||
(send-response #:body body)))
|
||||
(define upath (string-intersperse (map ->string (cdr (uri-path (request-uri (current-request))))) "/"))
|
||||
(cond ((equal? upath "")
|
||||
(send-response #:body (frontend-lookup "index.html")))
|
||||
(else
|
||||
(let ((maybe-asset (frontend-lookup upath #f)))
|
||||
(cond (maybe-asset
|
||||
(send-response
|
||||
#:headers (let ((ext (car (reverse (string-split upath ".")))))
|
||||
(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
|
||||
(if ssl?
|
||||
|
|
|
@ -4,5 +4,4 @@ import react from '@vitejs/plugin-react'
|
|||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
base: '/brm/inv/dist',
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue