ServerVariables Class
A collection of server variables defined in dedicated server configuration.
Examples
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
read-only names: string[];
A list of available, configured server variables.
Type: string[]
Methods
get
"get"(name: string): any | undefined
Returns the value of variable that has been configured in a dedicated server configuration JSON file.
Parameters
- name: string
Returns any | undefined
Important
This function can't be called in read-only mode.
Examples
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);
}
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for