根据uri模式(Apache)确定变量

问题描述 投票:0回答:1

实际上,我们正在使用Apache网络服务器来托管我们的REST-API。脚本是用Lua编写的,并使用mod-lua进行映射。

例如,httpd.conf中的实际代码段:

[...]
LuaMapHandler /restapi/(v\d{3})/(\w+) /opt/http/htdocs/restscripts/$1/$2.lua
[...]

因此,请求GET https://xxx/restapi/v001/articles被映射到脚本/opt/http/htdocs/restscripts/v001/articles.lua

[好,我希望你能真正跟随我。现在,我们必须使用模块扩展API,但请求uri必须相同。是否有机会确定模块名称并将其写入变量?


示例-脚本路径:

/opt/http/htdocs/restscripts/module1/v001/articles.lua
/opt/http/htdocs/restscripts/module2/v001/orders.lua
/opt/http/htdocs/restscripts/module2/v001/payments.lua
/opt/http/htdocs/restscripts/module3/v001/employees.lua

lua脚本是唯一的。

示例-请求:

GET https://xxx/restapi/v001/articles
GET https://xxx/restapi/v001/orders
GET https://xxx/restapi/v001/payments
GET https://xxx/restapi/v001/employees

httpd.conf应该像这样:

[...]
$MODULE=getModule
LuaMapHandler /restapi/(v\d{3})/(\w+) /opt/http/htdocs/restscripts/$MODULE/$1/$2.lua
[...]

我已经阅读了question之后的内容,但是这些变量与uri无关。

请告诉我,如果您需要任何其他信息。谢谢

apache rest centos rhel mod-lua
1个回答
0
投票

通过在uri中指定模块并在lua脚本中对其求值来解决。

© www.soinside.com 2019 - 2024. All rights reserved.