Skip to content

Commit

Permalink
[automated commit] Bump docs to versions 2.18.0, 1.53.4
Browse files Browse the repository at this point in the history
  • Loading branch information
leorossi authored and github-actions[bot] committed Nov 26, 2024
1 parent f3a14b7 commit f46ce6e
Show file tree
Hide file tree
Showing 187 changed files with 139 additions and 29 deletions.
83 changes: 69 additions & 14 deletions docs/packages/node/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,61 @@ You are all set, you can now start your runtime as usual via `wattpm dev` or `pl
}
```

## Specify service info

Some info can be specified for the node services. Currently for this few lines of code must be added.

### OpenAPI and GraphQL schema

It's possible for the node services to expose the OpenAPI or GraphQL schemas, if any.
This can be done adding few lines of code, e.g. for fastify:

```javascript
import fastify from 'fastify'
import fastifySwagger from '@fastify/swagger'

export async function build () {

const server = fastify({
loggerInstance: globalThis.platformatic?.logger
})

await server.register(fastifySwagger, {
openapi: {
openapi: '3.0.0',
info: {
title: 'Test Fastify API',
description: 'Testing the Fastify swagger API',
version: '0.1.0'
},
}
})

server.addHook('onReady', async () => {
const schema = server.swagger()
globalThis.platformatic.setOpenapiSchema(schema)
})
```
### Connection String
It's possible to specify if a node service uses a connection string (and which one).
This is useful to map which service uses which database and to potentialy track database changes.
```javascript
import { createServer } from "node:http";

globalThis.platformatic.setConnectionString(
"postgres://dbuser:dbpass@mydbhost/apidb",
);

const server = createServer((_req, res) => {
res.end(JSON.stringify({ ok: true }));
});

server.listen(1);
```
## Architecture
If your server entrypoint exports a `create` or `build` function, then Platformatic Node will execute it and then will wait for it to return a server object. In this situation the server will be used without starting a TCP server. The TCP server is started if the service is the runtime entrypoint.
Expand All @@ -43,37 +98,37 @@ In all cases, Platformatic runtime will modify the server port replacing it with
### Fastify with build function
```js
import fastify from 'fastify'
import fastify from "fastify";

export function create() {
const app = fastify({
logger: { level: globalThis.platformatic?.logLevel ?? 'info' }
})
logger: { level: globalThis.platformatic?.logLevel ?? "info" },
});

const prefix = globalThis.platformatic?.basePath ?? ''
const prefix = globalThis.platformatic?.basePath ?? "";

app.get(`${prefix}/env`, async () => {
return { production: process.env.NODE_ENV === 'production' }
})
return { production: process.env.NODE_ENV === "production" };
});

return app
return app;
}
```
### Express with no build function
```js
import express from 'express'
import express from "express";

const app = express()
const app = express();

const prefix = globalThis.platformatic?.basePath ?? ''
const prefix = globalThis.platformatic?.basePath ?? "";

app.get(`${prefix}/env`, (req, res) => {
res.send({ production: process.env.NODE_ENV === 'production' })
})
res.send({ production: process.env.NODE_ENV === "production" });
});

app.listen(3000)
app.listen(3000);
```
### Typescript
Expand Down Expand Up @@ -115,4 +170,4 @@ See the [configuration](./configuration.md) page.
- **`platformatic.logLevel`**: The log level configured for the service.
- **`platformatic.events.on('close')`**: This event is emitted when the process is being closed. A listener should be installed to perform a graceful close, which must finish in 10 seconds. If there is no listener, the process will be terminated by invoking `process.exit(0)`.
<Issues />
<Issues />
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,61 @@ You are all set, you can now start your runtime as usual via `wattpm dev` or `pl
}
```

## Specify service info

Some info can be specified for the node services. Currently for this few lines of code must be added.

### OpenAPI and GraphQL schema

It's possible for the node services to expose the OpenAPI or GraphQL schemas, if any.
This can be done adding few lines of code, e.g. for fastify:

```javascript
import fastify from 'fastify'
import fastifySwagger from '@fastify/swagger'

export async function build () {

const server = fastify({
loggerInstance: globalThis.platformatic?.logger
})

await server.register(fastifySwagger, {
openapi: {
openapi: '3.0.0',
info: {
title: 'Test Fastify API',
description: 'Testing the Fastify swagger API',
version: '0.1.0'
},
}
})

server.addHook('onReady', async () => {
const schema = server.swagger()
globalThis.platformatic.setOpenapiSchema(schema)
})
```
### Connection String
It's possible to specify if a node service uses a connection string (and which one).
This is useful to map which service uses which database and to potentialy track database changes.
```javascript
import { createServer } from "node:http";

globalThis.platformatic.setConnectionString(
"postgres://dbuser:dbpass@mydbhost/apidb",
);

const server = createServer((_req, res) => {
res.end(JSON.stringify({ ok: true }));
});

server.listen(1);
```
## Architecture
If your server entrypoint exports a `create` or `build` function, then Platformatic Node will execute it and then will wait for it to return a server object. In this situation the server will be used without starting a TCP server. The TCP server is started if the service is the runtime entrypoint.
Expand All @@ -43,37 +98,37 @@ In all cases, Platformatic runtime will modify the server port replacing it with
### Fastify with build function
```js
import fastify from 'fastify'
import fastify from "fastify";

export function create() {
const app = fastify({
logger: { level: globalThis.platformatic?.logLevel ?? 'info' }
})
logger: { level: globalThis.platformatic?.logLevel ?? "info" },
});

const prefix = globalThis.platformatic?.basePath ?? ''
const prefix = globalThis.platformatic?.basePath ?? "";

app.get(`${prefix}/env`, async () => {
return { production: process.env.NODE_ENV === 'production' }
})
return { production: process.env.NODE_ENV === "production" };
});

return app
return app;
}
```
### Express with no build function
```js
import express from 'express'
import express from "express";

const app = express()
const app = express();

const prefix = globalThis.platformatic?.basePath ?? ''
const prefix = globalThis.platformatic?.basePath ?? "";

app.get(`${prefix}/env`, (req, res) => {
res.send({ production: process.env.NODE_ENV === 'production' })
})
res.send({ production: process.env.NODE_ENV === "production" });
});

app.listen(3000)
app.listen(3000);
```
### Typescript
Expand Down Expand Up @@ -115,4 +170,4 @@ See the [configuration](./configuration.md) page.
- **`platformatic.logLevel`**: The log level configured for the service.
- **`platformatic.events.on('close')`**: This event is emitted when the process is being closed. A listener should be installed to perform a graceful close, which must finish in 10 seconds. If there is no listener, the process will be terminated by invoking `process.exit(0)`.
<Issues />
<Issues />
2 changes: 1 addition & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[
"2.17.0",
"2.18.0",
"1.53.4"
]

0 comments on commit f46ce6e

Please sign in to comment.