コンテンツにスキップ

Address

Address は、mixi2 Application API の公式エンドポイント/アドレスを定数として提供するヘルパーです。環境変数や設定ファイルに固定値を持たせる必要がなくなり、コード上で明示的に参照できます。

追加インストールは不要です。mixi2-js に同梱されています。

// ESM
import { tokenUrl, apiAddress, streamAddress } from 'mixi2-js/helpers';
// CJS
const { tokenUrl, apiAddress, streamAddress } = require('mixi2-js/helpers');

アクセストークンの取得 URL や API サーバーアドレスは固定値ですが、手入力やコピペではミスが起きやすいです。

// ❌ 固定値を手書き
const authenticator = new OAuth2Authenticator({
clientId,
clientSecret,
tokenUrl: 'https://application-auth.mixi.social/oauth2/token',
});
const client = new Client({
apiAddress: 'application-api.mixi.social',
authenticator,
});

Address を使えば、公式の値をそのまま再利用できます:

// ✅ 公式アドレスを参照
const authenticator = new OAuth2Authenticator({
clientId,
clientSecret,
tokenUrl,
});
const client = new Client({
apiAddress,
authenticator,
});
import {
OAuth2Authenticator,
Client,
StreamWatcher,
} from 'mixi2-js';
import { tokenUrl, apiAddress, streamAddress } from 'mixi2-js/helpers';
const authenticator = new OAuth2Authenticator({
clientId: process.env.CLIENT_ID!,
clientSecret: process.env.CLIENT_SECRET!,
tokenUrl,
});
const client = new Client({
apiAddress,
authenticator,
});
const watcher = new StreamWatcher({
streamAddress,
authenticator,
});
定数説明
tokenUrlstringアクセストークン取得用エンドポイント URL
apiAddressstringgRPC API サーバーアドレス
streamAddressstringgRPC ストリーミング接続用サーバーアドレス
定数
tokenUrlhttps://application-auth.mixi.social/oauth2/token
apiAddressapplication-api.mixi.social
streamAddressapplication-stream.mixi.social