参考文献:https://zh.javascript.info/fetch-crossorigin

示例代码:

  • Vercel REST API:
import { VercelRequest, VercelResponse } from '@vercel/node';
module.exports = async (req: VercelRequest, res: VercelResponse) => {
    const key = req.query.key;
    let data: any;
    if (key === "passwd") {
        data = `checkPass("ok")`;
    }
    else {
        data = `checkPass("no")`;
    }
    res.status(200).send(data);
}
  • 前端:
let pass = prompt('Type it:','');
let theScript = document.createElement('script');
theScript.src = `https://pass-api-seven.vercel.app/api/god?key=${pass}`;
document.head.append(theScript);
function checkPass(msg) {
    if (msg === "ok") {
        //authorised
    } else {
        //unauthorized
    }
}
- Total words: 131 -