export default function* (url) { let matchedService; for (let service of services) { matchedService = yield service.match(url); if (matchedService) { const result = yield service.parseUrl(url); return yield service.lookupId(result.id, result.type); } } };
const server = http.createServer( ( request, response ) => { const parsedUrl = parseUrl( request.url ); const urlPath = parsedUrl.pathname, searchParams = parsedUrl.searchParams; // save existing file if ( searchParams && searchParams.saveFile ) { const fullpath = path.resolve( runDir, searchParams.saveFile ); statfile( fullpath ) .then( stats => { let res = []; request.on( 'data', ( d, err ) => { if ( !err ) { res.push( d ); } } ); request.on( 'end', () => { const filedata = JSON.parse( Buffer.concat( res ).toString() ).data; saveFile( fullpath, filedata ) .then( () => { response.writeHead( 200, { 'Content-Type': 'text/html' } ); response.end( fullpath ); } ); } ); } ); return; } if ( urlPath === intialFile ) { viewFile( `${baseDir}/views/web-editor.html`, baseDir ) .then( templatefile => { const filedata = templatefile.toString(); response.writeHead( 200, { 'Content-Type': 'text/html' } ); response.end( filedata ); } ); return; } else if ( urlPath === '/favicon.ico' || urlPath.indexOf( '/node_modules' ) > -1 ) { response.writeHead( 404, { 'Content-Type': 'text/html' } ); response.end(); return; } listDir( `${runDir}/${urlPath}`, response ); } );