CORS制限を回避するモジュール
CORS対応済みのURLは素通し
既に CORS 対応済みの代表的なサービスの URL(例: Imgur、Wikipedia、Unsplash)や
Base64 埋め込み形式の data URI は、そのまま返す設計。
→ 既に安全にアクセスできるものは手を加えず、可用性を落とさない。
その他の URL は自動でプロキシ経由
上記以外の URL は、公開・無認証のプロキシをランダムで経由して安全に取得。
使用するプロキシ例:
余計な機能なし
エクスポートされる関数は corsKiller
ただ1つ。
引数は文字列、返り値も文字列のシンプル設計。
Node.js / ブラウザ対応
型安全な TypeScript で両環境で利用可能
おんJ民が作っている
質問や相談はフォーラムで: 質問フォーラム
npm i @onjmin/cors-killer
import { corsKiller } from "@onjmin/cors-killer";
const url = "https://example.com/image.png"; // CORS非対応
const safeUrl = corsKiller(url);
console.log(safeUrl); // CORS対応済みURL
// https://api.allorigins.win/raw?url=https://example.com/image.png
const { corsKiller } = await import("https://cdn.jsdelivr.net/npm/@onjmin/cors-killer/dist/index.min.mjs");
const url = "https://example.com/image.png"; // CORS非対応
const safeUrl = corsKiller(url);
console.log(safeUrl); // CORS対応済みURL
// https://api.allorigins.win/raw?url=https://example.com/image.png
LICENSE
をご覧ください。