浏览代码

feat: allow dns prefetch & remove timestamp prop

Sven 2 年之前
父节点
当前提交
fa6d415394
共有 5 个文件被更改,包括 16 次插入28 次删除
  1. 12 24
      README.md
  2. 1 0
      changelog.md
  3. 3 1
      src/server.ts
  4. 0 2
      src/types.d.ts
  5. 0 1
      src/utils.ts

+ 12 - 24
README.md

@@ -125,8 +125,7 @@ These are the available routes:
 >         // This array contains up to 10 objects with the same structure as 'top', sorted best match first
 >         // The amount of objects in here is the same as the 'matches' property
 >         // The first object of this array is exactly the same as 'top'
->     ],
->     "timestamp": 1234567890123
+>     ]
 > }
 > ```
 >
@@ -138,8 +137,7 @@ These are the available routes:
 > {
 >     "error": true,
 >     "matches": null,
->     "message": "Something went wrong",
->     "timestamp": 1234567890123
+>     "message": "Something went wrong"
 > }
 > ```
 >
@@ -151,8 +149,7 @@ These are the available routes:
 > {
 >     "error": true,
 >     "matches": 0,
->     "message": "Found no results matching your search query",
->     "timestamp": 1234567890123
+>     "message": "Found no results matching your search query"
 > }
 > ```
 >
@@ -239,8 +236,7 @@ These are the available routes:
 >         "image": "https://images.genius.com/..."
 >     },
 >     "lyricsState": "complete",
->     "id": 42069,
->     "timestamp": 1234567890123
+>     "id": 42069
 > }
 > ```
 >
@@ -252,8 +248,7 @@ These are the available routes:
 > {
 >     "error": true,
 >     "matches": null,
->     "message": "Something went wrong",
->     "timestamp": 1234567890123
+>     "message": "Something went wrong"
 > }
 > ```
 >
@@ -265,8 +260,7 @@ These are the available routes:
 > {
 >     "error": true,
 >     "matches": 0,
->     "message": "Found no results matching your search query",
->     "timestamp": 1234567890123
+>     "message": "Found no results matching your search query"
 > }
 > ```
 >
@@ -310,8 +304,7 @@ These are the available routes:
 >             "path": "/Genius-traducciones-al-espanol-artist-song-al-espanol-lyrics",
 >             "id": 6942
 >         }
->     ],
->     "timestamp": 1234567890123
+>     ]
 > }
 > ```
 >
@@ -323,8 +316,7 @@ These are the available routes:
 > {
 >     "error": true,
 >     "matches": null,
->     "message": "Something went wrong",
->     "timestamp": 1234567890123
+>     "message": "Something went wrong"
 > }
 > ```
 >
@@ -336,8 +328,7 @@ These are the available routes:
 > {
 >     "error": true,
 >     "matches": 0,
->     "translations": [],
->     "timestamp": 1234567890123
+>     "translations": []
 > }
 > ```
 >
@@ -379,8 +370,7 @@ These are the available routes:
 >             "image": "https://images.genius.com/...",
 >             "headerImage": "https://images.genius.com/..."
 >         }
->     },
->     "timestamp": 1234567890123
+>     }
 > }
 > ```
 >
@@ -392,8 +382,7 @@ These are the available routes:
 > {
 >     "error": true,
 >     "matches": null,
->     "message": "Something went wrong",
->     "timestamp": 1234567890123
+>     "message": "Something went wrong"
 > }
 > ```
 >
@@ -405,8 +394,7 @@ These are the available routes:
 > {
 >     "error": true,
 >     "matches": 0,
->     "message": "Couldn't find any associated album for this song",
->     "timestamp": 1234567890123
+>     "message": "Couldn't find any associated album for this song"
 > }
 > ```
 >

+ 1 - 0
changelog.md

@@ -14,6 +14,7 @@
 - Fixed inconsistent `error` property when no translations are found
 - Added support for preflight through an OPTIONS request
 - Improved rate-limit header consistency
+- Removed timestamp property to allow for better caching
 - Made documentation more clear
 
 <br>

+ 3 - 1
src/server.ts

@@ -15,7 +15,9 @@ const { env } = process;
 const app = express();
 
 app.use(cors({ methods: "GET,HEAD,OPTIONS", origin: "*" }));
-app.use(helmet());
+app.use(helmet({ 
+    dnsPrefetchControl: true,
+}));
 app.use(express.json());
 app.use(compression({ threshold: 256 }));
 

+ 0 - 2
src/types.d.ts

@@ -5,14 +5,12 @@ export type ServerResponse<T> = SuccessResponse<T> | ErrorResponse;
 export type SuccessResponse<T> = {
     error: false;
     matches: number;
-    timestamp: number;
 } & T;
 
 export type ErrorResponse = {
     error: true;
     matches: 0 | null;
     message: string;
-    timestamp: number;
 }
 
 //#SECTION meta

+ 0 - 1
src/utils.ts

@@ -62,7 +62,6 @@ export function respond(res: Response, type: ResponseType | number, data: String
         error,
         ...(matches === undefined ? {} : { matches }),
         ...resData,
-        timestamp: Date.now(),
     };
 
     const finalData = format === "xml" ? jsonToXml("data", resData) : resData;