ソースを参照

Make scrape endpoint function async

Tati 7 年 前
コミット
172bc488fe
1 ファイル変更4 行追加5 行削除
  1. 4 5
      ktchn/src/recipes/scrape/index.ts

+ 4 - 5
ktchn/src/recipes/scrape/index.ts

@@ -21,17 +21,16 @@ export const parseIngredients = (rawIngredient: string): Ingredient => {
   };
 };
 
-function scrape(url:string) {
+async function scrape(url:string) {
   const options = {
     uri: url,
     transform: (body: any) => Cheerio.load(body, {
       normalizeWhitespace: true
     }),
   };
-  return RequestPromise(options).then(($) => {
-    let source = selectSource(url);
-    return source ? source.scrapeRecipe($) : new Error('source not found');
-  });
+  const $ = await RequestPromise(options);
+  let source = selectSource(url);
+  return source ? source.scrapeRecipe($) : new Error('source not found');
 
 }