For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /server-admin/classes/ServerSecrets.md.

Class: ServerSecrets

Beta

表示在专用服务器配置中定义的服务器机密变量的集合。

A collection of server secrets defined in dedicated server configuration.

Example

getPlayerProfile.ts

import { variables, secrets } from '@minecraft/server-admin';
import { http, HttpRequest, HttpRequestMethod, HttpHeader, HttpResponse } from '@minecraft/server-net';

const serverUrl = variables.get('serverEndpoint');

function getPlayerProfile(playerId: string): Promise<HttpResponse> {
  const req = new HttpRequest(serverUrl + 'getPlayerProfile');

  req.body = JSON.stringify({
    playerId,
  });

  const authTokenSec = secrets.get('authtoken');

  if (!authTokenSec) {
    throw new Error('authtoken secret not defined.');
  }

  req.method = HttpRequestMethod.Post;
  req.headers = [new HttpHeader('Content-Type', 'application/json'), new HttpHeader('auth', authTokenSec)];

  return http.request(req);
}

Properties

names

readonly names: string[]

Beta

Remarks

已配置且可用的服务器机密变量名称组成的数组。

A list of available, configured server secrets.

Methods

get()

get(name): SecretString | undefined

World Mutation Early Execution Beta

Parameters

name

string

Returns

SecretString | undefined

Remarks

以占位符形式返回在专用服务器配置 JSON 文件中定义的指定机密变量。 在特定的对象(例如 HttpHeader)中,机密变量占位符会在执行时被替换为实际的值,但脚本本身是无法访问该值的。

Returns a SecretString that is a placeholder for a secret configured in a JSON file. In certain objects, like an HttpHeader, this Secret is resolved at the time of execution but is not made available to the script environment.