Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
server
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tools
server
Commits
fb90904b
Commit
fb90904b
authored
Apr 29, 2019
by
Fred Chasen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
keep browser connection alive
parent
90d11eb5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
24 deletions
+34
-24
app.js
src/app.js
+17
-8
printer.js
src/printer.js
+17
-16
No files found.
src/app.js
View file @
fb90904b
...
...
@@ -13,13 +13,16 @@ const requestLogger = require('koa-logger');
const
validate
=
require
(
'
koa-validate
'
);
const
mount
=
require
(
'
koa-mount
'
);
const
pdf
=
require
(
'
./pdf
'
);
const
printer
=
require
(
'
./printer
'
);
// const pdf = require('./pdf');
// const Printer = require('pagedjs-cli');
const
printerRoute
=
require
(
'
./printer
'
);
const
app
=
new
Koa
();
const
router
=
new
Router
();
router
.
post
(
'
/
'
,
printer
);
router
.
post
(
'
/
'
,
printer
Route
);
app
.
use
(
cors
());
...
...
@@ -36,16 +39,22 @@ app.use(bodyParser(
validate
(
app
);
//
app.use(ctx => {
//
console.log(ctx.request.body
);
// app.use((ctx, next) => {
//
ctx.printer = printer;
//
next(
);
// });
app
.
use
(
router
.
routes
())
app
.
listen
(
PORT
,
()
=>
{
let
server
=
app
.
listen
(
PORT
,
()
=>
{
console
.
warn
(
`Printer server listening on
${
PORT
}
, in
${
process
.
env
.
NODE_ENV
}
mode`
);
});
process
.
on
(
'
SIGTERM
'
,
()
=>
{
console
.
log
(
'
Closing http server.
'
);
printer
.
close
();
server
.
close
();
});
module
.
exports
=
app
;
src/printer.js
View file @
fb90904b
const
fs
=
require
(
'
fs
'
);
const
Printer
=
require
(
'
pagedjs-cli
'
);
const
printer
=
new
Printer
();
printer
.
setup
();
printer
.
on
(
"
page
"
,
(
page
)
=>
{
console
.
debug
(
"
Rendering: Page
"
+
(
page
.
position
+
1
))
});
printer
.
on
(
"
rendered
"
,
(
msg
)
=>
{
console
.
debug
(
"
Generating
"
);
});
printer
.
on
(
"
postprocessing
"
,
(
msg
)
=>
{
console
.
debug
(
"
Processing
"
);
});
module
.
exports
=
async
(
ctx
)
=>
{
ctx
.
type
=
'
application/pdf
'
;
ctx
.
attachment
(
'
out.pdf
'
);
const
{
url
,
html
,
options
,
headers
}
=
ctx
.
request
.
body
;
//
console.debug('URL: ', url);
// console.debug('HTML: ', html
);
console
.
debug
(
'
URL:
'
,
url
);
console
.
debug
(
'
HTML:
'
,
html
&&
html
.
length
);
// console.debug('OPTIONS: ', options);
// console.debug('HEADERS: ', headers);
let
printer
=
new
Printer
();
printer
.
on
(
"
page
"
,
(
page
)
=>
{
console
.
debug
(
"
Rendering: Page
"
+
(
page
.
position
+
1
))
});
printer
.
on
(
"
rendered
"
,
(
msg
)
=>
{
console
.
debug
(
"
Generating
"
);
});
printer
.
on
(
"
postprocessing
"
,
(
msg
)
=>
{
console
.
debug
(
"
Processing
"
);
});
let
file
;
if
(
url
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment