Sfoglia il codice sorgente

fixed wrong content-type + readme stuff

Sv443 3 anni fa
parent
commit
aaa1f07fd1
2 ha cambiato i file con 6 aggiunte e 3 eliminazioni
  1. 2 2
      README.md
  2. 4 1
      src/server.js

+ 2 - 2
README.md

@@ -1,7 +1,7 @@
 # geniURL
 
-Simple JSON and XML "REST proxy" to search for song and lyrics metadata on [genius.](https://genius.com/)  
-Obtaining actual lyrics sadly isn't possible yet.
+Simple JSON and XML REST API to search for song metadata and the lyrics URL on [genius](https://genius.com/)  
+Obtaining actual lyrics sadly isn't possible yet (ideas are welcome lol)
 
 <br><br>
 

+ 4 - 1
src/server.js

@@ -87,7 +87,7 @@ function registerEndpoints()
             const meta = await getMeta(q);
 
             // js2xmlparser needs special treatment when using arrays to produce a good XML structure
-            const response = format === "xml" ? { top: meta.top, all: { "result": meta.all } } : meta;
+            const response = format !== "xml" ? meta : { ...meta, all: { "result": meta.all } };
 
             return respond(res, "success", response, req?.query?.format);
         });
@@ -154,6 +154,8 @@ function respond(res, type, data, format)
             break;
     }
 
+    const mimeType = format !== "xml" ? "application/json" : "application/xml";
+
     resData = {
         error,
         ...resData,
@@ -162,6 +164,7 @@ function respond(res, type, data, format)
 
     const finalData = format === "xml" ? jsonToXml.parse("data", resData) : resData;
 
+    res.setHeader("Content-Type", mimeType);
     res.status(statusCode).send(finalData);
 }