Skip to content

Commit

Permalink
fix: readme
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickleet committed Nov 12, 2022
1 parent 0dc8ec2 commit a834907
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,65 @@
# knative-microservice

Create an express server with handlers from a folder registered for cloudevents from KNative Eventing, logging set up, and a shutdown function.

## without persistence layer

```js
const { server, logger, onListen, shutdown } = await microservice({
handlers: {
path: "/handlers",
options: {
enableSyncSendToDenormalizer: true,
enableEventPublishing: true,
},
},
logger: pino(),
});

server.listen(port, onListen(port));
process.on("SIGTERM", shutdown());
```

## with persistence layer

```js
const connectionOptions = {
type: "postgres" as const,
url: sourced.psql.url,
schema: sourced.psql.schema,
synchronize: sourced.psql.synchronize,
extra: {
ssl: {
rejectUnauthorized: sourced.psql.ssl.rejectUnauthorized,
},
},
};

logger.info({
msg: "⏳ connecting to psql",
sync: connectionOptions.synchronize,
schema: connectionOptions.schema,
});
try {
await persistenceLayer.connect(connectionOptions);
} catch (error) {
logger.error({ msg: "🚨 Error connecting to psql", error });
process.exit(1);
}
logger.info("✅ connected to psql");

const { server, shutdown, onListen } = await microservice({
handlers: {
path: handlersPath,
options: {
enableSyncSendToDenormalizer: config.enableSyncSendToDenormalizer,
enableEventPublishing: config.enableEventPublishing,
},
},
logger,
});

server.listen(port, onListen(port));

process.on("SIGTERM", shutdown(persistenceLayer));
```

0 comments on commit a834907

Please sign in to comment.