I am trying to create a custom lua plugin for the APISIX docker version 2.15.0. I am using the a slightly different apisix example plugin and I am loading it using the instructions in the Developer Guide. However when I am reloading APISIX I get the following error and the plugin is not loading:
2022/10/05 14:05:40 [alert] 1#1: failed to load the 'resty.core' module (https://github.com/openresty/lua-resty-core); ensure you are using an OpenResty release from https://openresty.org/en/download.html (reason: /usr/local/apisix/apisix/plugins/3rd-party.lua:18: loop or previous error loading module 'apisix.core') in /usr/local/apisix/conf/nginx.conf:404
To reporduce:
- Clone the APISIX docker repo with the docker compose stack
- Create the folder
<repo>/example/plugins
- Create a file named
3rd-party.lua
and put the code below - Edit the
<repo>/apisix_conf/config.yaml
and add the lineextra_lua_path: "/usr/local/apisix/apisix/plugins/3rd-party.lua"
underapisix
- Bind the lua script to the docker by adding the line
- ./plugins/3rd-party.lua:/usr/local/apisix/apisix/plugins/3rd-party.lua
under theapisix
'svolumes
section - Run the docker stack with
cd ./example && docker-compose up -d
- See if the plugin is loaded.
The lua plugin code:
local require = require
local core = require("apisix.core")
local plugin_name = "3rd-party"
local schema = {
type = "object",
properties = {
body = {
description = "body to replace response.",
type = "string"
},
},
required = {"body"},
}
local plugin_name = "3rd-party"
local _M = {
version = 0.1,
priority = 12,
name = plugin_name,
schema = schema,
}
function _M.check_schema(conf)
return core.schema.check(schema, conf)
end
function _M.access(conf, ctx)
return 200, conf.body
end
return _M