Closed EaxMov closed 1 year ago
import pywss def cors(ctx: pywss.Context): if ctx.method == pywss.MethodOptions: ctx.set_header("Access-Control-Allow-Origin", "*") ctx.set_header("Access-Control-Expose-Headers", "*") ctx.set_header("Access-Control-Allow-Credentials", "true") ctx.set_header("Access-Control-Allow-Methods", "GET,POST,PUT,OPTIONS") return ctx.next() if __name__ == '__main__': app = pywss.App() app.use(cors) # 注册全局中间件 app.options("*", lambda ctx: None) # 注册options路由 app.run()