dihmeetree opened a new issue, #12190:
URL: https://github.com/apache/apisix/issues/12190
### Description
Hi guys I'm trying to get a custom plugin to work.
Here is my very basic plugin code:
```lua
local core = require("apisix.core")
-- Declare the plugin's name
local plugin_name = "hello"
-- Define the plugin schema
local plugin_schema = {
type = "object",
properties = {},
required = {},
}
-- Define the plugin with its version, priority, name, and schema
local _M = {
version = 0.1,
priority = 2000,
name = plugin_name,
schema = plugin_schema
}
-- Function to check if the plugin configuration is correct
function _M.check_schema(conf)
return core.schema.check(plugin_schema, conf)
end
-- Function to be called during the access phase
function _M.access(conf, ctx)
return 200, { message = "hit example plugin" }
end
-- Return the plugin so it can be used by APISIX
return _M
```
I've added the neccesary Lua load option in my config file like so:
```yaml
apisix:
# ...
# Path where plugins are located
extra_lua_path: "/opt/?.lua"
```
Then I added a route like so to test the plugin
```
curl "http://127.0.0.1:9180/apisix/admin/routes/hello" -H "X-API-KEY:
edd1c9f034335f136f87ad84b625c8f1" -X PUT -d '
{
"name": "hello-route",
"methods": [
"GET"
],
"uri": "/hello",
"upstream_id":"1",
"plugins": {
"hello": {}
}
}'
```
Doing this curl for the plugins list does return the hello plugin
```
curl http://localhost:9180/apisix/admin/plugins/list -H "X-API-KEY:
edd1c9f034335f136f87ad84b625c8f1
```
which returns
```
["hello","limit-count","prometheus","log-rotate"]
```
I should be able to go to the `/hello` route and see the custom message from
the plugin no? However I do not, I just see the stuff from my upstream app
instead.
Any idea's what i'm doing wrong?
### Environment
- APISIX version (run `apisix version`): Running in docker so it's:
apache/apisix:3.12.0-debian
- Operating system (run `uname -a`): linux (Docker)
- OpenResty / Nginx version (run `openresty -V` or `nginx -V`): Whatever is
in the apache/apisix:3.12.0-debian image
- etcd version, if relevant (run `curl
http://127.0.0.1:9090/v1/server_info`): bitnami/etcd:3.5.21 Docker image
- APISIX Dashboard version, if relevant:
- Plugin runner version, for issues related to plugin runners:
- LuaRocks version, for installation issues (run `luarocks --version`):
--
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]