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/port
|
||||||
racket/match
|
racket/match
|
||||||
racket/pretty
|
racket/pretty
|
||||||
racket/cmdline
|
|
||||||
web-server/servlet-env
|
web-server/servlet-env
|
||||||
web-server/servlet
|
web-server/servlet
|
||||||
"../make/make-structs.rkt"
|
"../make/make-structs.rkt"
|
||||||
|
@ -15,7 +14,6 @@
|
||||||
"../parser/parse-bytecode.rkt"
|
"../parser/parse-bytecode.rkt"
|
||||||
"../compiler/compiler.rkt"
|
"../compiler/compiler.rkt"
|
||||||
"../js-assembler/assemble.rkt"
|
"../js-assembler/assemble.rkt"
|
||||||
"write-runtime.rkt"
|
|
||||||
(for-syntax racket/base))
|
(for-syntax racket/base))
|
||||||
|
|
||||||
(define-runtime-path htdocs (build-path "htdocs"))
|
(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))]))
|
|
||||||
|
|
||||||
|
(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 port))))
|
||||||
|
|
||||||
(write-repl-runtime-files)
|
(module+ main
|
||||||
(serve/servlet start
|
(define current-port (make-parameter 8080))
|
||||||
#:servlet-path "/compile"
|
(require racket/cmdline)
|
||||||
#:extra-files-paths (list htdocs)
|
(void (command-line
|
||||||
#:launch-browser? #f
|
#:once-each
|
||||||
#:port (current-port))
|
[("-p" "--port") p "Port (default 8080)"
|
||||||
|
(current-port (string->number p))]))
|
||||||
|
(start-server #:port (current-port)))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user