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 |
---|---|---|
|
Takes a pre-built Gracile handler from |
|
|
|
‐ |
Returns
Example
/src/server.js
import expressfunction express(): core.Express
Creates 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(): Express
Creates an Express application. The express() function is a top-level function exported by the express module.
();
appconst app: Express
.useApplication<Record<string, any>>.use: (...handlers: RequestHandler<ParamsDictionary, any, any, QueryString.ParsedQs, Record<string, any>>[]) => Express (+8 overloads)
(gracilemodule "@gracile/gracile/node"
.nodeAdapterfunction nodeAdapter(handler: GracileHandler, options?: NodeAdapterOptions): gracile.GracileNodeHandler
export nodeAdapter
(handlerimport handler
));
const serverconst server: Server<typeof IncomingMessage, typeof ServerResponse>
= appconst app: Express
.listenApplication<Record<string, any>>.listen(callback?: () => void): Server<typeof IncomingMessage, typeof ServerResponse> (+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);
();
Defined in
packages/engine/dist/server/adapters/node.d.ts:24
Function: honoAdapter()
function honoAdapter(handler, options?): GracileHonoHandler;
Parameters
Parameter | Type | Description |
---|---|---|
|
Takes a pre-built Gracile handler from |
|
|
|
If you need more control. |
Returns
Example
/src/server.js
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 { serveconst serve: (options: Options, listeningListener?: ((info: AddressInfo) => void) | undefined) => ServerType
} from '@hono/node-server';
import * as gracilemodule "@gracile/gracile/hono"
from '@gracile/gracile/hono';
import { handlerimport handler
} from './dist/server/entrypoint.js';
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, "/">
.useHono<BlankEnv, BlankSchema, "/">.use: MiddlewareHandlerInterface
<BlankEnv>(...handlers: MiddlewareHandler<BlankEnv, never, {}>[]) => Hono<{}, BlankSchema, "/"> (+20 overloads)
(gracilemodule "@gracile/gracile/hono"
.honoAdapterfunction honoAdapter(handler: GracileHandler, options?: HonoAdapterOptions): gracile.GracileHonoHandler
export honoAdapter
(handlerimport handler
));
servefunction serve(options: Options, listeningListener?: ((info: AddressInfo) => void) | undefined): ServerType
(appconst app: Hono<BlankEnv, BlankSchema, "/">
);
Defined in
packages/engine/dist/server/adapters/hono.d.ts:30
Function: getClientBuildPath()
function getClientBuildPath(root): string;
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: (options?: ServeStaticOptions) => MiddlewareHandler
} 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
<"*", "*", HandlerResponse<any>, {}, any>(path: "*", handler: H<any, "*", {}, HandlerResponse<any>>) => Hono<BlankEnv, {
"*": {
$get: {
input: {};
output: {};
outputFormat: string;
status: StatusCode;
} | {
...;
};
};
}, "/"> (+22 overloads)
(
'*',
serveStaticfunction serveStatic(options?: ServeStaticOptions): MiddlewareHandler
({ rootroot?: string | undefined
Root path, relative to current working directory from which the app was started. Absolute paths are not supported.
: gracilemodule "@gracile/gracile/node"
.getClientBuildPathfunction getClientBuildPath(root: string): string
export getClientBuildPath
(import.meta.urlImportMeta.url: string
The absolute file:
URL of the module.
) }),
);
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 |
---|---|---|
|
|
packages/engine/dist/server/constants.d.ts:25 |
|
|
packages/engine/dist/server/constants.d.ts:22 |
|
|
packages/engine/dist/server/constants.d.ts:21 |
|
|
packages/engine/dist/server/constants.d.ts:20 |
|
|
packages/engine/dist/server/constants.d.ts:24 |
|
|
packages/engine/dist/server/constants.d.ts:23 |
Example
/src/server.js
import * as gracilemodule "@gracile/gracile/hono"
from '@gracile/gracile/hono';
import { serveconst serve: (options: Options, listeningListener?: ((info: AddressInfo) => void) | undefined) => ServerType
} from '@hono/node-server';
// ...
servefunction serve(options: Options, listeningListener?: ((info: AddressInfo) => void) | undefined): ServerType
({ fetchfetch: FetchCallback
: app.fetch, portport?: number | undefined
: 3030, hostnamehostname?: string | undefined
: gracilemodule "@gracile/gracile/hono"
.serverconst server: Readonly<{
LOCALHOST: "localhost";
IP_LOCALHOST: "127.0.0.1";
IP_EXPOSED: "0.0.0.0";
RANDOM_PORT: 0;
PUBLIC_DIR: "public";
CLIENT_DIST_DIR: "./dist/client";
}>
export server
Server constants.
Useful for setting up your HTTP framework options.
.LOCALHOSTtype LOCALHOST: "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 |
---|---|
|
|
|
|
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 |
---|---|
|
|
|
|
|
|
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 |
---|---|---|
|
|
packages/internal/utils/dist/node-condition/production-ssr.d.ts:17 |
|
|
packages/internal/utils/dist/node-condition/production-ssr.d.ts:18 |
|
|
packages/internal/utils/dist/node-condition/production-ssr.d.ts:19 |
|
|
packages/internal/utils/dist/node-condition/production-ssr.d.ts:20 |
Example
📄 /src/lib/my-lib.ts
import { envimport env
} from '@gracile/gracile/env';
if (envimport 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 |
---|---|
|
|
|
|
|
|
|
|
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 |
---|---|---|
|
|
Takes an |
Returns
void
Example
import * as gracilemodule "@gracile/gracile/hono"
from '@gracile/gracile/hono';
import { serveconst serve: (options: Options, listeningListener?: ((info: AddressInfo) => void) | undefined) => ServerType
} from '@hono/node-server';
// ...
servefunction serve(options: Options, listeningListener?: ((info: AddressInfo) => void) | undefined): ServerType
({ fetchfetch: FetchCallback
: app.fetch, portport?: number | undefined
: 3030, hostnamehostname?: string | undefined
: 'localhost' }, (addressaddress: AddressInfo
) =>
gracilemodule "@gracile/gracile/hono"
.printUrlsfunction printUrls(server: string | AddressInfo | null): void
export printUrls
Pretty print your server instance address as soon as it is listening.
Matches the dev. server CLI output style.
(addressaddress: AddressInfo
),
);
Defined in
packages/engine/dist/server/utils.d.ts:20