File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -23,13 +23,23 @@ const getIndexContent = (options, callback) => {
23
23
const getIndexTemplate = ( options , callback ) => {
24
24
try {
25
25
const url = `${ options . root } /${ templateName } `
26
+ httpGet ( url , callback )
27
+ } catch ( err ) {
28
+ callback ( err )
29
+ }
30
+ }
31
+
32
+ const httpGet = ( url , callback ) => {
33
+ try {
26
34
const isHttps = new URL ( url ) . protocol === 'https:'
27
35
const get = isHttps ? https . get : http . get
28
- get ( url , resp => {
36
+ get ( url , res => {
37
+ const { statusCode } = res
38
+ if ( statusCode !== 200 ) callback ( new Error ( `Status Code ${ statusCode } ` ) )
29
39
let data = ''
30
- resp . on ( 'data' , chunk => { data += chunk } )
31
- resp . on ( 'end' , ( ) => { callback ( null , data ) } )
32
- resp . on ( 'err' , callback )
40
+ res . on ( 'data' , chunk => { data += chunk } )
41
+ res . on ( 'end' , ( ) => { callback ( null , data ) } )
42
+ res . on ( 'err' , callback )
33
43
} )
34
44
} catch ( err ) {
35
45
callback ( err )
You can’t perform that action at this time.
0 commit comments