improve nginx conf.
All checks were successful
Deploy / Build (push) Successful in 5m42s

This commit is contained in:
amass 2025-01-03 23:31:53 +08:00
parent 25bc92a45d
commit 345b518d75
5 changed files with 16 additions and 115 deletions

View File

@ -138,11 +138,6 @@ Application::Application(const std::string &path)
session.reply(std::move(s));
});
m_router->insert("/trigger-ci.hook", [this](HttpSession &session, const Request &request, const boost::urls::matches &matches) {
LOG(info) << "webhook: " << request;
session.reply(ServiceLogic::make_200<boost::beast::http::string_body>(request, "Main page\n", "text/html"));
});
m_router->insert("/notify", [this](HttpSession &session, const Request &request, const boost::urls::matches &matches) {
auto corp = Amass::Singleton<CorporationContext>::instance();
corp->notify(request);

View File

@ -20,21 +20,26 @@ location /日常随笔 {
access_by_lua_file lua/authentication.lua;
}
location = /blog/profile {
content_by_lua_file lua/profile.lua;
}
location ^~ /api/v1/login {
# 应用限流规则,使用名称为 one 的限流区域,允许突发请求数为 5不延迟处理
limit_req zone=one burst=5 nodelay;
default_type 'application/json; charset=utf-8';
content_by_lua_file lua/login.lua;
}
location ^~ /api/v1/search/ {
proxy_pass http://meilisearch/;
}
location ^~ /api/v1/auth {
# 应用限流规则,使用名称为 one 的限流区域,允许突发请求数为 5不延迟处理
limit_req zone=one burst=5 nodelay;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header x-wiz-real-ip $remote_addr;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_pass http://wt;
}
location ~ ^/api/v1/.*$ {
proxy_pass http://local;
}
@ -84,10 +89,6 @@ location = /search/website_collections {
content_by_lua_file lua/request_website_collections.lua;
}
location ~ /trigger-ci.+$ {
proxy_pass http://local;
}
location ~ /notify.*$ {
proxy_pass http://local;
}

View File

@ -1,18 +1,3 @@
require "resty.session".init({
cookie_http_only=true,
remember = true,
storage = "cookie",
remember_rolling_timeout = 7200,
})
app_version="0.0.1"
private_folder = {"个人笔记"};
user_infomation = {
name = "Amass",
qq = "168062547",
phone = "15217052880",
user = user
};
user_password = "luo19961030";

View File

@ -1,60 +0,0 @@
local cjson = require "cjson"
local function add_domain(cookies, key, domain)
if type(cookies) == "string" then -- 确保 set_cookies 是一个表
cookies = { cookies }
end
local new_cookies = {} -- 查找并修改名为 'remember' 的 Cookie
for _, cookie in ipairs(cookies) do
local cookie_key, value = string.match(cookie, "^%s*(.-)%s*=%s*(.-)%s*;")
if cookie_key == key then
local new_cookie = value .. "; Domain=" .. domain .. "; Path=/; HttpOnly; SameSite=Lax"
table.insert(new_cookies, key.."=" .. new_cookie)
else
table.insert(new_cookies, cookie)
end
end
return new_cookies;
end
ngx.req.read_body()
local body = ngx.req.get_body_data()
if not body then
ngx.status = ngx.HTTP_BAD_REQUEST
ngx.say("No body found")
return
end
local ok, json_data = pcall(cjson.decode, body)
if not ok then
ngx.status = ngx.HTTP_BAD_REQUEST
ngx.say("Invalid JSON")
return
end
local user_account = json_data.account
local user_password = json_data.password
local reply = {}
local session = require "resty.session".start()
local accounts = require("lua/accounts")
local credentials = accounts.credentials()
if credentials and credentials[user_account] == user_password then
reply.status = 0
reply.message = "登录成功"
session:set("account", user_account)
session:set("authenticated", true)
session:save()
ngx.header["Set-Cookie"] = add_domain(ngx.header["Set-Cookie"], "remember", ".amass.fun");
else
reply.status = -100
reply.message = "登录失败"
end
ngx.say(cjson.encode(reply))

View File

@ -1,20 +0,0 @@
local cjson = require "cjson"
local session = require"resty.session".open()
local response = {}
if (session == nil or session.data.identify == nil) then
response.code = 1
response.message = "未登录,session is nil."
ngx.say(cjson.encode(response));
return
else
if (session.data.identify ~= "myself") then
response.code = 1
response.message = "未登录,identify:" .. session.data.identify
else
response.code = 0
response.user = user_infomation
end
ngx.say(cjson.encode(response));
end