standalone.ts — astro Source File
Architecture documentation for standalone.ts, a typescript file in the astro codebase. 10 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 61bdb796_7444_31bb_d2a3_47bbf4268895["standalone.ts"] 51a2098e_4246_bc69_a692_31865f56142c["./log-listening-on.js"] 61bdb796_7444_31bb_d2a3_47bbf4268895 --> 51a2098e_4246_bc69_a692_31865f56142c 0dad751c_0394_f4dd_ca31_364000581878["./serve-app.js"] 61bdb796_7444_31bb_d2a3_47bbf4268895 --> 0dad751c_0394_f4dd_ca31_364000581878 c896f375_b1d0_6436_3a22_d283efd5a73f["./serve-static.js"] 61bdb796_7444_31bb_d2a3_47bbf4268895 --> c896f375_b1d0_6436_3a22_d283efd5a73f b384cf30_390d_6db6_4724_be96d46e50ef["./types.js"] 61bdb796_7444_31bb_d2a3_47bbf4268895 --> b384cf30_390d_6db6_4724_be96d46e50ef e16a223b_37f3_6b25_1ee1_2b7bcb9d9415["node:fs"] 61bdb796_7444_31bb_d2a3_47bbf4268895 --> e16a223b_37f3_6b25_1ee1_2b7bcb9d9415 c2f6615e_96e9_c4eb_5f71_cf120e271705["node:http"] 61bdb796_7444_31bb_d2a3_47bbf4268895 --> c2f6615e_96e9_c4eb_5f71_cf120e271705 c3c33304_f44d_798a_9c7b_a80c587ed267["node:https"] 61bdb796_7444_31bb_d2a3_47bbf4268895 --> c3c33304_f44d_798a_9c7b_a80c587ed267 f16d8c76_2866_6150_bd14_0347b59abfe9["astro"] 61bdb796_7444_31bb_d2a3_47bbf4268895 --> f16d8c76_2866_6150_bd14_0347b59abfe9 8d666858_ab9a_2697_4536_5cb6ce038643["node"] 61bdb796_7444_31bb_d2a3_47bbf4268895 --> 8d666858_ab9a_2697_4536_5cb6ce038643 89910508_08ee_53bc_2fb7_02df7e8a3838["server-destroy"] 61bdb796_7444_31bb_d2a3_47bbf4268895 --> 89910508_08ee_53bc_2fb7_02df7e8a3838 style 61bdb796_7444_31bb_d2a3_47bbf4268895 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import fs from 'node:fs';
import http from 'node:http';
import https from 'node:https';
import type { PreviewServer } from 'astro';
import type { NodeApp } from 'astro/app/node';
import enableDestroy from 'server-destroy';
import { logListeningOn } from './log-listening-on.js';
import { createAppHandler } from './serve-app.js';
import { createStaticHandler } from './serve-static.js';
import type { Options } from './types.js';
// Used to get Host Value at Runtime
export const hostOptions = (host: Options['host']): string => {
if (typeof host === 'boolean') {
return host ? '0.0.0.0' : 'localhost';
}
return host;
};
export default function standalone(app: NodeApp, options: Options) {
const port = process.env.PORT ? Number(process.env.PORT) : (options.port ?? 8080);
const host = process.env.HOST ?? hostOptions(options.host);
const handler = createStandaloneHandler(app, options);
const server = createServer(handler, host, port);
server.server.listen(port, host);
if (process.env.ASTRO_NODE_LOGGING !== 'disabled') {
logListeningOn(app.getAdapterLogger(), server.server, host);
}
return {
server,
done: server.closed(),
};
}
// also used by server entrypoint
export function createStandaloneHandler(app: NodeApp, options: Options) {
const appHandler = createAppHandler(app, options);
const staticHandler = createStaticHandler(app, options);
return (req: http.IncomingMessage, res: http.ServerResponse) => {
try {
// validate request path
decodeURI(req.url!);
} catch {
res.writeHead(400);
res.end('Bad request.');
return;
}
staticHandler(req, res, () => appHandler(req, res));
};
}
// also used by preview entrypoint
export function createServer(listener: http.RequestListener, host: string, port: number) {
let httpServer: http.Server | https.Server;
if (process.env.SERVER_CERT_PATH && process.env.SERVER_KEY_PATH) {
httpServer = https.createServer(
{
key: fs.readFileSync(process.env.SERVER_KEY_PATH),
cert: fs.readFileSync(process.env.SERVER_CERT_PATH),
},
listener,
);
} else {
httpServer = http.createServer(listener);
}
enableDestroy(httpServer);
// Resolves once the server is closed
const closed = new Promise<void>((resolve, reject) => {
httpServer.addListener('close', resolve);
httpServer.addListener('error', reject);
});
const previewable = {
host,
port,
closed() {
return closed;
},
async stop() {
await new Promise((resolve, reject) => {
httpServer.destroy((err) => (err ? reject(err) : resolve(undefined)));
});
},
} satisfies PreviewServer;
return {
server: httpServer,
...previewable,
};
}
Domain
Subdomains
Dependencies
- ./log-listening-on.js
- ./serve-app.js
- ./serve-static.js
- ./types.js
- astro
- node
- node:fs
- node:http
- node:https
- server-destroy
Source
Frequently Asked Questions
What does standalone.ts do?
standalone.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, CoreMiddleware subdomain.
What functions are defined in standalone.ts?
standalone.ts defines 4 function(s): createServer, createStandaloneHandler, hostOptions, standalone.
What does standalone.ts depend on?
standalone.ts imports 10 module(s): ./log-listening-on.js, ./serve-app.js, ./serve-static.js, ./types.js, astro, node, node:fs, node:http, and 2 more.
Where is standalone.ts in the architecture?
standalone.ts is located at packages/integrations/node/src/standalone.ts (domain: CoreAstro, subdomain: CoreMiddleware, directory: packages/integrations/node/src).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free