feat: Node.js 环境规范化 profile-web-page-url 的值, 设置响应头失败时仅输出日志

This commit is contained in:
xream committed 2026-03-01 21:51:11 +08:00
1 parent cd023cd27a
commit 517136df2a
2 files changed
+37 -1

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.21.33",
"version": "2.21.34",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
"main": "src/main.js",
"scripts": {
+36
View File
@@ -31,6 +31,42 @@ export default function express({ substore: $, port, host }) {
bodyParser.urlencoded({ verify: rawBodySaver, extended: true }),
);
app.use(bodyParser.raw({ verify: rawBodySaver, type: '*/*' }));
app.use((req, res, next) => {
const originalSetHeader = res.setHeader.bind(res);
res.setHeader = function (name, value) {
function normalize(v) {
if (typeof v !== 'string') return v;
if (['profile-web-page-url'].includes(name.toLowerCase())) {
try {
const url = new URL(v);
return url.href; // 自动 punycode + 标准化
} catch {
return v;
}
}
return v;
}
try {
if (Array.isArray(value)) {
value = value.map(normalize);
} else {
value = normalize(value);
}
return originalSetHeader(name, value);
} catch (err) {
console.log(`Invalid header ignored\n${name}: ${value}`);
return this;
}
};
next();
});
app.use((_, res, next) => {
res.set(DEFAULT_HEADERS);
next();