bzp2010 commented on a change in pull request #6145: URL: https://github.com/apache/apisix/pull/6145#discussion_r790282220
########## File path: apisix/plugins/public-api.lua ########## @@ -0,0 +1,58 @@ +-- +-- Licensed to the Apache Software Foundation (ASF) under one or more +-- contributor license agreements. See the NOTICE file distributed with +-- this work for additional information regarding copyright ownership. +-- The ASF licenses this file to You under the Apache License, Version 2.0 +-- (the "License"); you may not use this file except in compliance with +-- the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +local core = require("apisix.core") +local router = require("apisix.router") + +local schema = { + type = "object", + properties = { + uri = {type = "string"}, + }, +} + + +local _M = { + version = 0.1, + priority = 501, + name = "public-api", + schema = schema, +} + + +function _M.check_schema(conf) + return core.schema.check(schema, conf) +end + + +function _M.access(conf, ctx) + local local_conf = core.config.local_conf() + + -- overwrite the uri in the ctx when the user has set the target uri + ctx.var.uri = conf.uri and conf.uri or ctx.var.uri + local skip = local_conf and local_conf.apisix.global_rule_skip_internal_api Review comment: ## Update After checking again, I think there may not be a duplicate calls problem. ## Details  There are **4** calls to `run_global_rules` executed in the current code. One of them is in `api_router`, which is controlled by the configuration file (this is the router used by the public API), and the remaining ones are executed in the `http_access_phase` of `init`. 1. both HTTP and public API do not match, will run and return a 404 status code 2. run after HTTP matched 3. run in `common_phase` for `before_proxy` In fact I didn't add `global_rules` to init.lua, they are still being executed according to the original logic. If I have missed anything, please help point it out. Thanks. ping @spacewander -- 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]
