Refresh the storefront and autoplay pack demos
Cache allowlisted official media so the in-game browser can load it locally. Match the official catalog snapshot and start pack demos muted and looping on entry.
This commit is contained in:
1 parent
81e3add520
commit
aa272fc82b
14 files changed
+645
-140
No files matched your search
@@ -39,11 +39,13 @@ export interface LogNotes {
|
||||
readonly redactedRequestBody?: string;
|
||||
readonly requestText?: string;
|
||||
readonly responseText?: string;
|
||||
/** Public media bytes can already be recovered from the local media cache. */
|
||||
readonly omitResponseBody?: boolean;
|
||||
}
|
||||
|
||||
/** A Gaijin service emulated by the local service (one protocol-layer module each). */
|
||||
export interface Service {
|
||||
readonly name: string;
|
||||
accepts(request: ServiceRequest): boolean;
|
||||
handle(request: ServiceRequest): ServiceResponse;
|
||||
handle(request: ServiceRequest): ServiceResponse | Promise<ServiceResponse>;
|
||||
}
|
||||
@@ -20,21 +20,23 @@ export type ConnectionNumbers = (socket: Socket) => number;
|
||||
|
||||
export function createHttpServer(router: Router, log: TrafficLog, connectionOf: ConnectionNumbers): Server {
|
||||
const server = createServer({ requestTimeout: 0, headersTimeout: 0, keepAliveTimeout: 0 }, (incoming, outgoing) => {
|
||||
readBody(incoming).then(
|
||||
void readBody(incoming).then(
|
||||
(body) => respond(incoming, outgoing, body),
|
||||
() => outgoing.writeHead(413).end(),
|
||||
);
|
||||
() => { outgoing.writeHead(413).end(); },
|
||||
).catch((error: Error) => outgoing.destroy(error));
|
||||
});
|
||||
|
||||
function respond(incoming: IncomingMessage, outgoing: ServerResponse, body: Buffer): void {
|
||||
async function respond(incoming: IncomingMessage, outgoing: ServerResponse, body: Buffer): Promise<void> {
|
||||
const target = parseRequestTarget(incoming.url ?? '/', incoming.headers.host);
|
||||
if (target.originalHost === undefined && target.path === HEALTH_PATH) {
|
||||
outgoing.writeHead(200, { 'content-type': 'application/json' }).end(JSON.stringify({ app: 'wto-local-service', pid: process.pid }));
|
||||
return;
|
||||
}
|
||||
const request: ServiceRequest = { method: incoming.method ?? 'GET', ...target, headers: incoming.headers, body };
|
||||
const { service, response } = router.route(request);
|
||||
log.exchange(request, service, response, connectionOf(incoming.socket));
|
||||
const connection = connectionOf(incoming.socket);
|
||||
const { service, response } = await router.route(request);
|
||||
if (outgoing.destroyed) return;
|
||||
log.exchange(request, service, response, connection);
|
||||
outgoing.writeHead(response.status, response.headers ?? {});
|
||||
outgoing.end(response.body ?? '');
|
||||
}
|
||||
|
||||
@@ -16,13 +16,13 @@ export class Router {
|
||||
this.#services = services;
|
||||
}
|
||||
|
||||
route(request: ServiceRequest): RoutedResponse {
|
||||
async route(request: ServiceRequest): Promise<RoutedResponse> {
|
||||
const service = this.#services.find((candidate) => candidate.accepts(request));
|
||||
if (!service) {
|
||||
return { service: 'none', response: { status: 404, body: 'no local service for this request', logNotes: { unhandled: true } } };
|
||||
}
|
||||
try {
|
||||
return { service: service.name, response: service.handle(request) };
|
||||
return { service: service.name, response: await service.handle(request) };
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.stack ?? error.message : String(error);
|
||||
return { service: service.name, response: { status: 500, body: 'local service error', logNotes: { summary: 'ERROR', responseText: message } } };
|
||||
|
||||
Reference in new issue
Block a user