@@ -6,25 +6,25 @@ const express = require('express');
66const cors = require ( 'cors' ) ;
77const codeToSVG = require ( '@js-basics/code-snippet-to-svg' ) ;
88
9- const githubRawUrl = 'https:// raw.githubusercontent.com' ;
9+ const githubRawUrl = 'raw.githubusercontent.com' ;
1010const app = express ( ) ;
1111app . use ( cors ( { origin : true } ) ) ;
1212
1313function getMinMax ( value = '1' ) {
1414 return value . split ( '-' ) ;
1515}
1616
17- function getCodeAsSVG ( path , range = '1' , lang , theme ) {
18- const url = githubRawUrl + path ;
17+ function getCodeAsSVG ( path , query ) {
18+ const url = `https:// ${ query . host || githubRawUrl } ${ path } ` ;
1919 return request ( { uri : url } ) . then ( ( code ) => {
20- const [ min , max ] = getMinMax ( range ) ;
21- return codeToSVG ( code , min , max , lang , theme ) ;
20+ const [ min , max ] = getMinMax ( query . range ) ;
21+ return codeToSVG ( code , min , max , query ) ;
2222 } ) ;
2323}
2424
2525app . get ( [ '/:account/:repo/*' ] , ( req , res ) => {
2626 const path = req . path . replace ( / ( [ \w - ] * \/ [ \w - ] * ) ( \/ b l o b ) / , '$1' ) ;
27- getCodeAsSVG ( path , req . query . range , req . query . lang , req . query . theme ) . then ( ( svg ) => {
27+ getCodeAsSVG ( path , req . query ) . then ( ( svg ) => {
2828 res . setHeader ( 'Content-Type' , 'image/svg+xml' ) ;
2929 res . send ( Buffer . from ( svg ) ) ;
3030 } ) ;
@@ -34,7 +34,7 @@ exports.default = functions.https.onRequest(app);
3434
3535exports . test = functions . https . onRequest ( ( req , res ) => {
3636 const path = '/GrabarzUndPartner/gp-vue-boilerplate/master/src/components/molecules/LinkList.vue' ;
37- getCodeAsSVG ( path , req . query . range , req . query . lang , req . query . theme ) . then ( ( svg ) => {
37+ getCodeAsSVG ( path , req . query ) . then ( ( svg ) => {
3838 res . setHeader ( 'Content-Type' , 'image/svg+xml' ) ;
3939 res . send ( Buffer . from ( svg ) ) ;
4040 } ) ;
0 commit comments