Skip to content

Commit f62fa68

Browse files
authored
Merge pull request #13 from uuanqin/master
修复 interceptorTemplate 不生效的问题
2 parents 19cd817 + 7551211 commit f62fa68

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

packages/link-interceptor/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ module.exports = function({whiteList, blackList, interceptorTemplate}) {
2222
return !inBlackList || inWhiteList;
2323
}
2424

25-
function outputHtml(url) {
26-
const template = interceptorTemplate || `<!DOCTYPE html><html lang="zh-CN"><head><title>Redirect to third party website</title></head><body data-url="__URL__"><p>Redirecting to __URL__</p><script>location.href = document.body.getAttribute('data-url');</script></body></html>`;
27-
return template.replace(/__URL__/g, () => url);
28-
}
29-
3025
function replaceUrl(text, redirectUrl = `${ctx.protocol}://${ctx.host}/api/redirect`) {
3126
return text.replace(/href\=\"([^"#]+)\"/g, (originText, url) => {
3227
if (isValidUrl(url)) {
@@ -54,6 +49,11 @@ module.exports = function({whiteList, blackList, interceptorTemplate}) {
5449
await next();
5550
},
5651
async (ctx, next) => {
52+
function outputHtml(url) {
53+
const template = interceptorTemplate || `<!DOCTYPE html><html lang="zh-CN"><head><title>Redirect to third party website</title></head><body data-url="__URL__"><p>Redirecting to __URL__</p><script>location.href = document.body.getAttribute('data-url');</script></body></html>`;
54+
return template.replace(/__URL__/g, () => url);
55+
}
56+
5757
if (ctx.path.toLowerCase() !== '/api/redirect' || ctx.method.toUpperCase() !== 'GET') {
5858
return next();
5959
}

0 commit comments

Comments
 (0)