Skip to content

Latest commit

 

History

History
264 lines (201 loc) · 5.47 KB

readme.md

File metadata and controls

264 lines (201 loc) · 5.47 KB


spectre

spectre Build Status

Highly concurrent, extensively configurable, necessarily stable export server 👻

Install

External Dependencies

Required
Optional
  • PDFtk 1 >= 2.x - only required for merging bulk pdf request into a single pdf

1: this dependency must be either (1) available directly in your path OR (2) the absolute path to the executable provided in the config

Clone

git clone https://github.com/brandon93s/spectre.git
cd spectre

Install Node Modules

npm install

Usage

// start spectre
npm start

// run tests
npm test

Examples

GET
// screenshot of github.com
GET /?url=github.com
// custom viewport size
GET /?url=github.com&width=700&height=450
// non-default file type
GET /?url=github.com&format=pdf
POST
// delay rendering 3 seconds
POST /
{
   "url":"github.com",
   "mode":"delay",
   "delay":3000
}
// bulk request
POST /
{
   "format":"pdf",
   "width":1920,
   "height":750,
   "paperSize":{
      "format":"Letter",
      "orientation":"landscape",
      "margin":"1cm"
   },
   "items":[
      {
         "url":"github.com"
      },
      {
         "url":"atom.io",
         "mode":"delay",
         "delay":350
      },
      {
         "url":"travis-ci.org",
         "width":1000
      }
   ]
}

Documentation

// todo

API

GET /

POST /

url

Required
Type: string

The url to request.

format

Type: string
Default: 'png'

The file format of the export.
Possible Values: 'png' 'jpg' 'gif' 'pdf'

width

Type: int
Default: 1366

The width of the viewport at the time of rendering.

height

Type: int
Default: 768

The height of the viewport at the time of rendering.

paperSize

Type: object

Defines the size of the web page when rendered as a PDF. If no paperSize is defined the size is defined by the web page.

Supported dimension units are: mm cm in px. No unit means px.
Supported formats are: 'A3' 'A4' 'A5' 'Legal' 'Letter' 'Tabloid'.
Supported orientations are: 'landscape' 'portrait'. Default is 'portrait'.

paperSize accepts objects in the following two formats:

// width, height, margin
{
	width: '400px',
	height: '900px',
	margin: '1cm'
}

// format, orientation, margin
{
	format: 'Letter',
	orientation: 'landscape',
	margin: '30px'
}
quality

Type: int
Default: 100

The quality of the rendered output. Option not available for format === 'png'.
Possible Values: 1 - 100

mode

Type: string
Default: 'auto'

The triggering mode that controls when to begin rendering.
Possible Values:

  • 'auto' - render immediately when the dom is ready
  • 'delay' - render after a user-defined amount of time
  • 'trigger' - trigger rendering from the page itself (w.i.p.)
delay

Type: int

When mode === 'delay' this value represents the amount of time to delay rendering in ms.

userAgent

Type: string
Default: PhantomJS default userAgent

The user agent string to send with the request.

enableJs

Type: bool
Default: true

Whether or not to load JavaScript in the target page.

loadImages

Type: bool
Default: true

Whether or not to load inlined images in the target page.

data

Type: object string

The data to send with the web page request.

Note: When data is present, the web page request is currently always a POST request.

dataType

Type: string
Default: 'urlencoded'

Defines the type of data to send with the web page request. Possible Values: 'urlencoded' 'json'

Note: Data is currently not converted to the correct type. This sets the correct headers for the request. Because of this 'urlencoded' expects a pre-formatted string and 'json' an object.

cookies

Type: array

An array of cookie objects with the following properties:

     name

     Required
     Type: string

     value

     Required
     Type: string, number, object

     path

     Required
     Type: string

     domain

     Type: string

     httponly

     Type: bool

     secure

     Type: bool

     expires

     Type: string

userName

Type: string

The user name used for HTTP Authentication

password

Type: string

The password used for HTTP Authentication

// todo
##### headers - custom KVP headers
##### timeout - web page request timeout
##### requestMethod - allow user to choose GET, POST, PUT, etc.

License

MIT © Brandon Smith