Server runtime

API references extracted from the Gracile code base.
Examples, functions, classes, constants, type declarations…

Function: nodeAdapter()

function nodeAdapter(handler, options?): GracileNodeHandler;

Parameters

Parameter Type Description

handler

GracileHandler

Takes a pre-built Gracile handler from ./dist/server/entrypoint.js.

options?

NodeAdapterOptions

Returns

GracileNodeHandler

Example

/src/server.js

import express from 'express';

import * as gracile from '@gracile/gracile/node';

import { handler } from './dist/server/entrypoint.js';

const app = express();

app.use(gracile.nodeAdapter(handler));

const server = app.listen();

Defined in

packages/engine/dist/server/adapters/node.d.ts:24

Function: honoAdapter()

function honoAdapter(handler, options?): GracileHonoHandler;

Parameters

Parameter Type Description

handler

GracileHandler

Takes a pre-built Gracile handler from ./dist/server/entrypoint.js.

options?

HonoAdapterOptions

If you need more control.

Returns

GracileHonoHandler

Example

/src/server.js

import { Hono } from 'hono';
import { serve } from '@hono/node-server';

import * as gracile from '@gracile/gracile/hono';

import { handler } from './dist/server/entrypoint.js';

const app = new Hono();

app.use(gracile.honoAdapter(handler));

serve(app);

Defined in

packages/engine/dist/server/adapters/hono.d.ts:30

Function: getClientBuildPath()

function getClientBuildPath(root): string;

Parameters

Parameter Type Description

root

string

resolve dist/client from this file path.

Returns

string

Example

/src/server.js

import * as gracile from '@gracile/gracile/node';
import { Hono } from 'hono';
import { serveStatic } from '@hono/node-server/serve-static';

const app = new Hono();

app.get(
  '*',
  serveStatic({ root: gracile.getClientBuildPath(import.meta.url) }),
);

Defined in

packages/engine/dist/server/adapters/hono.d.ts:46

Variable: server

const server: Readonly<object>;

Server constants. Useful for setting up your HTTP framework options.

Type declaration

Name Type Defined in

CLIENT_DIST_DIR

"./dist/client"

packages/engine/dist/server/constants.d.ts:25

IP_EXPOSED

"0.0.0.0"

packages/engine/dist/server/constants.d.ts:22

IP_LOCALHOST

"127.0.0.1"

packages/engine/dist/server/constants.d.ts:21

LOCALHOST

"localhost"

packages/engine/dist/server/constants.d.ts:20

PUBLIC_DIR

"public"

packages/engine/dist/server/constants.d.ts:24

RANDOM_PORT

0

packages/engine/dist/server/constants.d.ts:23

Example

/src/server.js

import * as gracile from '@gracile/gracile/hono';
import { serve } from '@hono/node-server';

// ...

serve({ fetch: app.fetch, port: 3030, hostname: gracile.server.LOCALHOST });

Defined in

packages/engine/dist/server/constants.d.ts:19

Type Alias: GracileHandler()

type GracileHandler: (request, locals?) => Promise<StandardResponse | ResponseWithNodeReadable | null>;

The underlying handler interface that you can use to build your own adapter.

Parameters

Parameter Type

request

Request

locals?

unknown

Returns

Promise<StandardResponse | ResponseWithNodeReadable | null>

Defined in

packages/engine/dist/server/request.d.ts:21

Type Alias: GracileNodeHandler()

type GracileNodeHandler: (request, response, locals?) => Promise<ServerResponse<IncomingMessage> | null | void>;

Parameters

Parameter Type

request

IncomingMessage

response

ServerResponse

locals?

unknown

Returns

Promise<ServerResponse<IncomingMessage> | null | void>

Defined in

packages/engine/dist/server/adapters/node.d.ts:3

Variable: nodeCondition

const nodeCondition: Readonly<object>;

Resolve environment from Node export conditions.

Type declaration

Name Type Defined in

BROWSER

boolean

packages/internal/utils/dist/node-condition/production-ssr.d.ts:17

DEV

boolean

packages/internal/utils/dist/node-condition/production-ssr.d.ts:18

PREVIEW

boolean

packages/internal/utils/dist/node-condition/production-ssr.d.ts:19

TEST

boolean

packages/internal/utils/dist/node-condition/production-ssr.d.ts:20

Example

📄 /src/lib/my-lib.ts

import { env } from '@gracile/gracile/env';

if (env.BROWSER) {
   Do stuff…
}

Defined in

packages/internal/utils/dist/node-condition/production-ssr.d.ts:16

Type Alias: GracileHonoHandler()

type GracileHonoHandler: (context) => Promise<Response>;

Parameters

Parameter Type

context

object

context.req

object

context.req.raw

Request

context.var

unknown

Returns

Promise<Response>

Defined in

packages/engine/dist/server/adapters/hono.d.ts:2

Function: printUrls()

function printUrls(server): void;

Pretty print your server instance address as soon as it is listening. Matches the dev. server CLI output style.

Parameters

Parameter Type Description

server

null | string | AddressInfo

Takes an node:net AddressInfo like object (address, family, port) or just a provided, pre-constructed string.

Returns

void

Example

import * as gracile from '@gracile/gracile/hono';
import { serve } from '@hono/node-server';

// ...

serve({ fetch: app.fetch, port: 3030, hostname: 'localhost' }, (address) =>
  gracile.printUrls(address),
);

Defined in

packages/engine/dist/server/utils.d.ts:20