Sn0rt commented on issue #9856: URL: https://github.com/apache/apisix/issues/9856#issuecomment-1641788241
You have 2 problems in this case 1. Serverless should not be used in this scenario, you can completely write a plug-in to achieve it. 2. Serverless cannot pass in program fragments, only one function can be passed in. https://apisix.apache.org/docs/apisix/plugins/serverless/  ```lua local core = require('apisix.core') local conf = { check_result = 'ok', body_schema = { properties = { method = { pattern = '^(?!aaa|bbb)', type = 'string' } }, required = {'method'}, type = 'object' } } return function(conf, ctx) core.ctx.register_var("check_result", function(ctx) local req_body local body, err = core.request.get_body() if not body then if err then core.log.error("failed to get body: ", err) end conf.check_result = "no" end local headers = core.request.headers(ctx) if headers["content-type"] == "application/x-www-form-urlencoded" then -- use 0 to avoid truncated result and keep the behavior as the -- same as other platforms req_body, err = ngx.decode_args(body, 0) else -- JSON as default req_body, err = core.json.decode(body) end if not req_body then core.log.error('failed to decode the req body: ', err) conf.check_result = "no" end local ok, err = core.schema.check(conf.body_schema, req_body) if not ok then core.log.error("req schema validation failed: ", err) conf.check_result = "no" end return conf.check_result end) end ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
