@@ -24,6 +24,31 @@ const r = new Router
2424const specRouter = new Router
2525
2626async function handle ( query , req , res , next ) {
27+ // '/pdf' | '/img'
28+ const {
29+ style,
30+ hlStyle,
31+ q,
32+ range,
33+ print,
34+ ...options
35+ } = query
36+ const url = join ( `http://localhost:${ port } /` , '?' + qs . stringify ( { style, q, hlStyle, range, print : true } ) )
37+ if ( options . hasOwnProperty ( '_force' ) ) {
38+ options . force = true
39+ delete options . _force
40+ }
41+
42+ const baseUrl = req . baseUrl
43+ switch ( baseUrl ) {
44+ case '/pdf' :
45+ res . type ( 'pdf' ) . send ( await headless . pdf ( url , options ) )
46+ return
47+ case '/img' :
48+ res . type ( 'image/png' ) . send ( await headless . img ( url , options ) )
49+ return
50+ }
51+
2752
2853 const appVM = AppVM . create ( { input : query . q , inputVisible : false , styleSelectVisible : false } )
2954 const telescope = appVM . telescope = new Telescope ( query )
@@ -57,44 +82,19 @@ ${query.print ? `<link rel="stylesheet" href="${join('/', req.baseUrl, 'print.cs
5782
5883async function handleExact ( req , res , next ) {
5984 const { branch, name, owner, 0 : filepath } = req . params
60-
6185 const query = req . url . indexOf ( '?' ) >= 0 ? parse ( req . url ) : { }
6286 query . q = `https://github.com/${ owner } /${ name } /${ branch || 'master' } /${ filepath || '' } `
6387
64-
65- // '/pdf' | '/img'
66- const {
67- style,
68- hlStyle,
69- q,
70- range,
71- print,
72- ...options
73- } = query
74- const url = join ( `http://localhost:${ port } /` , '?' + qs . stringify ( { style, q, hlStyle, range, print : true } ) )
75- // console.log(url)
76- if ( options . hasOwnProperty ( '_force' ) ) {
77- options . force = true
78- delete options . _force
79- }
80-
81- const baseUrl = req . baseUrl
82- switch ( baseUrl ) {
83- case '/pdf' :
84- res . type ( 'pdf' ) . send ( await headless . pdf ( url , options ) )
85- return
86- case '/img' :
87- res . type ( 'image/png' ) . send ( await headless . img ( url , options ) )
88- return
89- }
90-
91- // console.error(req.params, req.url, query)
9288 await handle ( query , req , res , next )
9389}
9490
9591specRouter . all ( '/' , async function ( req , res , next ) {
9692 const query = req . url . indexOf ( '?' ) >= 0 ? parse ( req . url ) : { }
93+ try {
9794 await handle ( query , req , res , next )
95+ } catch ( err ) {
96+ next ( err )
97+ }
9898} )
9999specRouter . all ( '/style.css' , function ( req , res ) {
100100 res . sendFile ( require . resolve ( '../client/index.css' ) , {
0 commit comments