Skip to content

Latest commit

 

History

History
74 lines (50 loc) · 3.46 KB

README.md

File metadata and controls

74 lines (50 loc) · 3.46 KB

fastify-cloudprnt

A fastify plugin to run a server that follows the Star Micronics CloudPRNT protocol.

Commit linting with Husky

The npm postinstall script has been removed as it fails on the GH action runner. If you would like lint-staged to run on each commit, run husky install manually.

Usage

import fastifyCloudPrnt from '@autotelic/fastify-cloudprnt'
import view from '@fastify/view'

export default async function basic (fastify, options) {
  // @fastify/view must be registered and available before fastify/view
  await fastify.register(view, viewConfig)

  await fastify.register(fastifyCloudPrnt, config)
}

Once the plugin is registered it exposes the CloudPRNT Protocol endpoints:

In addition it exposes:

  • POST /job to queue print jobs. Body:
{
  "token": <string>,
  "jobData": <object>
}

Returns 201 Created and echos the token back { "token": <string> }. The token should be a unique identifier for the print job - e.g. the order id if printing a receipt.

See API for config options.

See examples for working examples.

Template Rendering

Templates should be in Star Document Markup, and template rendering requires cputil to be in the path. The provided Dockerfile builds a container with the app and cputil in. Additionally, @fastify/view must be registered to fastify before fastify-cloudprnt.

Star Micronics provides a Star Document Markup Designer web app.

API

@autotelic/fastify-cloudprnt exports a fastify plugin. When registered the plugin expects a configuration object:

  • queueJob: (token, jobData) => any: method that takes a url-safe string token and an object of data jobData, to be passed to fastify point-of-view view method for template rendering, and adds the job to the print queue.
  • getJob: () => token: method that returns the url-safe string token for the next available print job on the queue.
  • getJobData: (token) => object: method that returns the data object for the job enqueued with the url-safe string token.
  • deleteJob: (token) => any: method that deletes the job enqueued with the url-safe string token from the print queue.
  • routePrefix: string: string which will configure a prefix for all cloudprint routes.

Examples

Basic

An example fastify app using node-cache. To run the basic example, use the following command:

  npm run example:basic

Redis

An example fastify app using redis. To run the redis example, use the following command:

  npm run example:redis