in the middle of sandboxing the compiler.
This commit is contained in:
parent
19a92c4b10
commit
1dfa615d5f
36
whalesong/repl-prototype/sandboxed-server.rkt
Normal file
36
whalesong/repl-prototype/sandboxed-server.rkt
Normal file
|
@ -0,0 +1,36 @@
|
|||
#lang racket
|
||||
|
||||
(require racket/sandbox
|
||||
racket/runtime-path
|
||||
setup/dirs
|
||||
racket/cmdline
|
||||
(for-syntax racket/base))
|
||||
|
||||
|
||||
(define current-port (make-parameter 8080))
|
||||
(void (command-line
|
||||
#:once-each
|
||||
[("-p" "--port") p "Port (default 8080)"
|
||||
(current-port (string->number p))]))
|
||||
|
||||
|
||||
|
||||
(define-runtime-path server-path (build-path "server.rkt"))
|
||||
|
||||
(define (my-network-guard name str port role)
|
||||
(printf "I see: ~s ~s ~s ~s\n" name str port role)
|
||||
#t)
|
||||
|
||||
|
||||
(define eval
|
||||
(parameterize ([sandbox-memory-limit 256]
|
||||
[sandbox-output (current-output-port)]
|
||||
[sandbox-network-guard my-network-guard])
|
||||
(printf "memory limit: ~s mb\n" (sandbox-memory-limit))
|
||||
(make-module-evaluator server-path
|
||||
#:allow-read (list (build-path "/")))))
|
||||
(printf "starting server thread\n")
|
||||
(define server-thread (eval `(start-server #:port ,(current-port))))
|
||||
(printf "thread started\n")
|
||||
|
||||
(sync server-thread)
|
|
@ -7,7 +7,6 @@
|
|||
racket/port
|
||||
racket/match
|
||||
racket/pretty
|
||||
racket/cmdline
|
||||
web-server/servlet-env
|
||||
web-server/servlet
|
||||
"../make/make-structs.rkt"
|
||||
|
@ -15,7 +14,6 @@
|
|||
"../parser/parse-bytecode.rkt"
|
||||
"../compiler/compiler.rkt"
|
||||
"../js-assembler/assemble.rkt"
|
||||
"write-runtime.rkt"
|
||||
(for-syntax racket/base))
|
||||
|
||||
(define-runtime-path htdocs (build-path "htdocs"))
|
||||
|
@ -120,16 +118,22 @@
|
|||
|
||||
|
||||
|
||||
(define current-port (make-parameter 8080))
|
||||
(void (command-line
|
||||
#:once-each
|
||||
[("-p" "--port") p "Port (default 8080)"
|
||||
(current-port (string->number p))]))
|
||||
|
||||
|
||||
(write-repl-runtime-files)
|
||||
(define (start-server #:port [port 8000])
|
||||
(thread (lambda ()
|
||||
(printf "starting web server on port ~s\n" port)
|
||||
(serve/servlet start
|
||||
#:servlet-path "/compile"
|
||||
#:extra-files-paths (list htdocs)
|
||||
#:launch-browser? #f
|
||||
#:port (current-port))
|
||||
#:port port))))
|
||||
|
||||
(module+ main
|
||||
(define current-port (make-parameter 8080))
|
||||
(require racket/cmdline)
|
||||
(void (command-line
|
||||
#:once-each
|
||||
[("-p" "--port") p "Port (default 8080)"
|
||||
(current-port (string->number p))]))
|
||||
(start-server #:port (current-port)))
|
||||
|
Loading…
Reference in New Issue
Block a user