Server runtime
API references extracted from the Gracile code base.
Examples, functions, classes, constants, type declarations…
Function: nodeAdapter()
function nodeAdapter(handler, options?): GracileNodeHandler;
Defined in: packages/engine/dist/server/adapters/node.d.ts:24
Parameters
| Parameter | Type | Description |
|---|---|---|
|
|
Takes a pre-built Gracile handler from |
|
|
|
|
‐ |
Returns
Example
/src/server.js
import expressfunction express(): ExpressCreates an Express application. The express() function is a top-level function exported by the express module.
from 'express';
import * as gracilemodule "@gracile/gracile/node" from '@gracile/gracile/node';
import { handlerimport handler } from './dist/server/entrypoint.js';
const appconst app: Express = expressfunction express(): ExpressCreates an Express application. The express() function is a top-level function exported by the express module.
();
appconst app: Express .useApplication<Record<string, any>>.use: <any, any, any, any, QueryString.ParsedQs, Record<string, any>>(path: any, ...handlers: RequestHandler<any, any, any, QueryString.ParsedQs, Record<string, any>>[]) => Express (+8 overloads) (gracilemodule "@gracile/gracile/node" .nodeAdapter(handlerimport handler ));
const serverconst server: Server<typeof IncomingMessage, typeof ServerResponse> = appconst app: Express .listenApplication<Record<string, any>>.listen(callback?: (error?: Error) => void): Server (+5 overloads)Listen for connections.
A node http.Server is returned, with this
application (which is a Function) as its
callback. If you wish to create both an HTTP
and HTTPS server you may do so with the "http"
and "https" modules as shown here:
var http = require('http')
, https = require('https')
, express = require('express')
, app = express();
http.createServer(app).listen(80);
https.createServer({ ... }, app).listen(443);
();
Function: getClientBuildPath()
function getClientBuildPath(root): string;
Defined in: packages/engine/dist/server/adapters/hono.d.ts:46
Parameters
| Parameter | Type | Description |
|---|---|---|
|
|
|
resolve |
Returns
string
Example
/src/server.js
import * as gracilemodule "@gracile/gracile/node" from '@gracile/gracile/node';
import { Honoclass Hono<E extends Env = BlankEnv, S extends Schema = BlankSchema, BasePath extends string = "/">The Hono class extends the functionality of the HonoBase class.
It sets up routing and allows for custom options to be passed.
} from 'hono';
import { serveStaticconst serveStatic: <E extends Env = any>(options?: ServeStaticOptions<E>) => MiddlewareHandler<E> } from '@hono/node-server/serve-static';
const appconst app: Hono<BlankEnv, BlankSchema, "/"> = new Hononew Hono<BlankEnv, BlankSchema, "/">(options?: HonoOptions<BlankEnv> | undefined): Hono<BlankEnv, BlankSchema, "/">Creates an instance of the Hono class.
();
appconst app: Hono<BlankEnv, BlankSchema, "/"> .getHono<BlankEnv, BlankSchema, "/", "/">.get: HandlerInterface
<"*", "*", Response, {}, any>(path: "*", handler: H<any, "*", {}, Response>) => Hono<BlankEnv, {
"*": {
$get: {
input: {};
output: {};
outputFormat: string;
status: StatusCode;
};
};
}, "/", "*"> (+22 overloads)
('*', serveStaticserveStatic<any>(options?: ServeStaticOptions<any> | undefined): MiddlewareHandler<any> ({ rootroot?: string | undefinedRoot path, relative to current working directory from which the app was started. Absolute paths are not supported.
: gracilemodule "@gracile/gracile/node" .getClientBuildPath(import.meta.urlImportMeta.url: string ) }));
Function: printUrls()
function printUrls(server): void;
Defined in: packages/engine/dist/server/utilities.d.ts:20
Pretty print your server instance address as soon as it is listening. Matches the dev. server CLI output style.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
|
|
Takes an |
Returns
void
Example
import * as gracilemodule "@gracile/gracile/hono" from '@gracile/gracile/hono';
import { serveconst serve: (options: Options, listeningListener?: (info: AddressInfo) => void) => ServerType } from '@hono/node-server';
// ...
servefunction serve(options: Options, listeningListener?: (info: AddressInfo) => void): ServerType (
{ fetchfetch: FetchCallback : app.fetch, portport?: number | undefined : 3030, hostnamehostname?: string | undefined : 'localhost' },
(addressaddress: AddressInfo ) => gracilemodule "@gracile/gracile/hono" .printUrls(addressaddress: AddressInfo ),
);
Variable: server
const server: Readonly<{
CLIENT_DIST_DIR: "./dist/client";
IP_EXPOSED: "0.0.0.0";
IP_LOCALHOST: "127.0.0.1";
LOCALHOST: "localhost";
PUBLIC_DIR: "public";
RANDOM_PORT: 0;
}>;
Defined in: packages/engine/dist/server/constants.d.ts:19
Server constants. Useful for setting up your HTTP framework options.
Example
/src/server.js
import * as gracilemodule "@gracile/gracile/hono" from '@gracile/gracile/hono';
import { serveconst serve: (options: Options, listeningListener?: (info: AddressInfo) => void) => ServerType } from '@hono/node-server';
// ...
servefunction serve(options: Options, listeningListener?: (info: AddressInfo) => void): ServerType (
{ fetchfetch: FetchCallback : app.fetch, portport?: number | undefined : 3030, hostnamehostname?: string | undefined : gracilemodule "@gracile/gracile/hono" .server.LOCALHOST },
);
Variable: nodeCondition
const nodeCondition: Readonly<{
BROWSER: boolean;
DEV: boolean;
PREVIEW: boolean;
TEST: boolean;
}>;
Defined in: packages/internal/utils/dist/node-condition/production-ssr.d.ts:16
Resolve environment from Node export conditions.
Example
📄 /src/lib/my-lib.ts
import { nodeConditionconst nodeCondition: Readonly<{
BROWSER: boolean;
DEV: boolean;
PREVIEW: boolean;
TEST: boolean;
}>
Resolve environment from Node export conditions.
} from '@gracile/gracile/node-condition';
if (nodeConditionconst nodeCondition: Readonly<{
BROWSER: boolean;
DEV: boolean;
PREVIEW: boolean;
TEST: boolean;
}>
Resolve environment from Node export conditions.
.BROWSERtype BROWSER: boolean ) {
Do stuff…
}
Type Alias: GracileHandler
type GracileHandler = (request, locals?) => Promise<HandlerResult>;
Defined in: packages/engine/dist/server/request.d.ts:11
The underlying handler interface that you can use to build your own adapter.
Parameters
| Parameter | Type |
|---|---|
|
|
|
|
|
|
Returns
Promise<HandlerResult>
Type Alias: GracileNodeHandler
type GracileNodeHandler = (request, response, locals?) => Promise<ServerResponse<IncomingMessage> | null | void>;
Defined in: packages/engine/dist/server/adapters/node.d.ts:3
Parameters
| Parameter | Type |
|---|---|
|
|
|
|
|
|
|
|
|
Returns
Promise<ServerResponse<IncomingMessage> | null | void>
Type Alias: GracileHonoHandler
type GracileHonoHandler = (context) => Promise<Response>;
Defined in: packages/engine/dist/server/adapters/hono.d.ts:2
Parameters
| Parameter | Type |
|---|---|
|
|
{ |
|
|
{ |
|
|
|
|
|
|
Returns
Promise<Response>