作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
问题说明了一切。本教程:https://www.html5rocks.com/en/tutorials/cors/说,至少,添加一个 Access-Control-Allow-Origin: *
服务器响应的 header 。
我的应用程序,运行 Hunchentoot,没有返回它:
<!-- GET http://127.0.0.1:9000/ -->
<!-- HTTP/1.1 200 OK -->
<!-- Date: Fri, 13 Oct 2017 23:26:58 GMT -->
<!-- Server: Hunchentoot 1.2.37 -->
<!-- Keep-Alive: timeout=20 -->
<!-- Connection: Keep-Alive -->
<!-- Transfer-Encoding: chunked -->
<!-- Content-Type: text/html;charset=utf-8 -->
<!-- Request duration: 0.004275s -->
(in-package :cl-user)
(defpackage lisp-todo
(:use :cl
:lucerne)
(:export :app)
(:documentation "Main lisp-todo code."))
(in-package :lisp-todo)
(defun change-headers (headers)
(setf (lack.response:response-headers *response*) headers))
package lack.response does not exist.
(setf (hunchentoot:header-out "Access-Control-Allow-Origin") "*")
the variable Hunchentoot:*reply* is unbound.
def-unbound
定义的.
(in-package :cl-user)
(defpackage todobackend-ningle
(:use :cl))
(in-package :todobackend-ningle)
;; blah blah blah.
(defvar *response* nil "") ;; to try the snippet below
(defun change-headers (headers)
;; (setf (lack.response:response-headers *response*) headers)) ;; => the value nil is not of type lack.response:response
(setf (lack.response:response-headers lack.response:response) headers)) ;; => unbound
(defvar *app* (make-instance 'ningle:<app>))
(change-headers '(:access-control-allow-origin "*"))
(setf (ningle:route *app* "/")
(lambda (params) ;; is that right ?
(change-headers '(:access-control-allow-origin "*"))
"Welcome to ningle!"))
最佳答案
这是我用于 Clack with Ningle 的代码,希望它可以帮助您:
(defpackage ...
(:use :cl :ningle))
(in-package ...)
(defun change-headers (headers)
(setf (lack.response:response-headers *response*) headers))
(defmacro api-route (url method en-tetes &body corps)
`(setf (ningle:route *app* ,url :method ,method)
;; that's why your code doesn't work, you actually have to pass a #'function
#'(lambda (params)
(change-headers ,headers)
,@corps)))
*response*
来自
ningle.context ,根据文件中的注释,我可能用错了它。
(api-route
"/"
:get
'(:access-control-allow-origin "*")
"Welcome!")
GET
来说已经足够了。请求,但对于其他动词,浏览器将首先点击
OPTIONS
.你必须至少用这些标题来回答它:
'(:access-control-allow-methods "POST" ; or any other verb(s)
:access-control-allow-origin "*"
:access-control-allow-headers "content-type")
关于common-lisp - 如何在 Hunchentoot 或 Clack 中启用 CORS,或者如何添加特定标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46739404/
我是一名优秀的程序员,十分优秀!