Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional configurations to run HTTPS/ IPPS print server. #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,14 @@ Bonjour/Zeroconf and write all jobs to the current working directory.
var fs = require('fs')
var Printer = require('ipp-printer')

var printer = new Printer('My Printer')
var printer = new Printer({
name: 'ipp-printer',
// optional
sslConfig: {
cert: fs.readFileSync('path_to_ssl_cert_file'),
key: fs.readFileSync('path_to_ssl_key_file'),
},
})

printer.on('job', function (job) {
console.log('[job %d] Printing document: %s', job.id, job.name)
Expand Down Expand Up @@ -165,6 +172,11 @@ An array of all jobs handled by the printer.

An instance of [`http.Server`](https://nodejs.org/api/http.html#http_class_http_server).

#### `printer.sslConfig`

Config options of type https://nodejs.org/api/tls.html#tlscreateserveroptions-secureconnectionlistener
in order to enable SSL/ TLS on the printer server.

### Class: Job

A job is a readable stream containing the document to be printed. In
Expand Down
6 changes: 5 additions & 1 deletion lib/bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var util = require('util')
var os = require('os')
var http = require('http')
var https = require('https')
var Bonjour = require('bonjour')
var ipp = require('ipp-encoder')
var debug = require('debug')(require('../package').name)
Expand All @@ -19,6 +20,9 @@ module.exports = function (printer) {
server.on('request', onrequest)
if (server.address()) onlistening()
else server.on('listening', onlistening)
} else if (printer.sslConfig) {
server = printer.server = https.createServer(printer.sslConfig, onrequest)
server.listen(printer.port, onlistening)
} else {
server = printer.server = http.createServer(onrequest)
server.listen(printer.port, onlistening)
Expand Down Expand Up @@ -76,7 +80,7 @@ module.exports = function (printer) {
function onlistening () {
printer.port = server.address().port

if (!printer.uri) printer.uri = 'ipp://' + os.hostname() + ':' + printer.port + '/'
if (!printer.uri) printer.uri = (printer.sslConfig? 'ipps://': 'ipp://') + os.hostname() + ':' + printer.port + '/'

debug('printer "%s" is listening on %s', printer.name, printer.uri)
printer.start()
Expand Down
1 change: 1 addition & 0 deletions lib/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function Printer (opts) {
this.state = C.STOPPED
this.server = opts.server
this.fallback = opts.fallback
this.sslConfig = opts.sslConfig

bind(this)
}
Expand Down
Loading