@@ -136,15 +136,14 @@ async function globHandler (req, res, next) {
136136 // TODO: This is a hack, that does not check if the target file exists, as this is quite complex with globbing.
137137 // TODO: Proper support for this is not implemented, as globbing support might be removed in the future.
138138 const filename = ldp . resourceMapper . getFilePath ( req )
139- const requestUri = ( await ldp . resourceMapper . mapFileToUrl ( { path : filename , hostname : req . hostname } ) ) . url
140139
141140 const globOptions = {
142141 noext : true ,
143142 nobrace : true ,
144143 nodir : true
145144 }
146145
147- glob ( filename , globOptions , function ( err , matches ) {
146+ glob ( filename , globOptions , async ( err , matches ) => {
148147 if ( err || matches . length === 0 ) {
149148 debugGlob ( 'No files matching the pattern' )
150149 return next ( error ( 404 , 'No files matching glob pattern' ) )
@@ -154,7 +153,7 @@ async function globHandler (req, res, next) {
154153 const globGraph = $rdf . graph ( )
155154
156155 debugGlob ( 'found matches ' + matches )
157- Promise . all ( matches . map ( match => new Promise ( async ( resolve , reject ) => {
156+ await Promise . all ( matches . map ( match => new Promise ( async ( resolve , reject ) => {
158157 const urlData = await ldp . resourceMapper . mapFileToUrl ( { path : match , hostname : req . hostname } )
159158 fs . readFile ( match , { encoding : 'utf8' } , function ( err , fileData ) {
160159 if ( err ) {
@@ -178,15 +177,15 @@ async function globHandler (req, res, next) {
178177 } )
179178 } )
180179 } ) ) )
181- . then ( ( ) => {
182- const data = $rdf . serialize ( undefined , globGraph , requestUri , 'text/turtle' )
183- // TODO this should be added as a middleware in the routes
184- res . setHeader ( 'Content-Type' , 'text/turtle' )
185- debugGlob ( 'returning turtle')
186-
187- res . send ( data )
188- return next ( )
189- } )
180+
181+ const requestUri = ldp . resourceMapper . getRequestUrl ( req )
182+ const data = $rdf . serialize ( undefined , globGraph , requestUri , 'text/turtle' )
183+ // TODO this should be added as a middleware in the routes
184+ res . setHeader ( 'Content-Type' , 'text/ turtle')
185+ debugGlob ( 'returning turtle' )
186+
187+ res . send ( data )
188+ next ( )
190189 } )
191190}
192191
0 commit comments