-
Notifications
You must be signed in to change notification settings - Fork 1
/
fcg-server.lisp
81 lines (62 loc) · 3.17 KB
/
fcg-server.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
;; Copyright 2022-present Sony Computer Science Laboratories Paris
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
;; You may obtain a copy of the License at
;; http://www.apache.org/licenses/LICENSE-2.0
;; Unless required by applicable law or agreed to in writing, software
;; distributed under the License is distributed on an "AS IS" BASIS,
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;; See the License for the specific language governing permissions and
;; limitations under the License.
;;=========================================================================
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; This file contains all code concerning the set-up of an FCG server ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(in-package :hunchentoot)
;; This file contains prototype code that was developed for research purposes and should not be used in production environments.
;; No warranties are provided.
(export '(fcg-acceptor))
(defclass fcg-acceptor (easy-acceptor)
())
(defmethod acceptor-dispatch-request ((acceptor fcg-acceptor) request)
(loop for dispatcher in *dispatch-table*
for action = (funcall dispatcher request)
when action return (funcall action)
finally (call-next-method)))
(defmethod acceptor-dispatch-request :around ((acceptor fcg-acceptor) request)
(declare (ignore request))
(setf (header-out "Access-Control-Allow-Origin") "*")
(setf (header-out "Access-Control-Allow-Headers") "Content-Type,Accept,Origin")
(setf (header-out "Content-Type") "application/json")
(call-next-method))
(in-package :fcg-server)
(defvar *fcg-server* nil
"Global variable that holds the FCG server")
(defun start-fcg-server (&key (address "127.0.0.1")
(port 1170)
(grammar-systems '(:fcg)))
"Starting up the fcg-server..."
(ql:quickload grammar-systems)
(if *fcg-server*
(warn (format nil "Server already running at ~a:~a" (hunchentoot:acceptor-address *fcg-server*) (hunchentoot:acceptor-port *fcg-server*)))
(progn
(push (snooze:make-hunchentoot-app) hunchentoot:*dispatch-table*)
(setf *fcg-server* (hunchentoot:start (make-instance 'hunchentoot::fcg-acceptor :address address :port port)))
(format t "***** started FCG server at ~a:~a *****" (hunchentoot:acceptor-address *fcg-server*) (hunchentoot:acceptor-port *fcg-server*))
*fcg-server*)))
;; (start-fcg-server)
(defun stop-fcg-server ()
"Stops the FCG server."
(when *fcg-server*
(hunchentoot:stop *fcg-server*)
(setf *fcg-server* nil)))
;; (stop-fcg-server)
(defmethod explain-condition ((condition http-condition)
resource
ct)
"Send back detailed error reports."
(encode-json-to-string
`((:status-code . ,(format nil "~a" (status-code condition)))
(:error-message . ,(simple-condition-format-control condition)))))