From a8faeb2d83ab53ba0934b512343c468e345e521c Mon Sep 17 00:00:00 2001
From: Galax
Date: Mon, 15 Nov 2021 09:36:13 +0700
Subject: [PATCH] Added CORS proxy serverless
---
api/index.js | 16 ++++++++++++++++
package.json | 3 +++
public/index.html | 4 ++--
src/components/ts/Search.tsx | 7 +------
vercel.json | 3 +++
5 files changed, 25 insertions(+), 8 deletions(-)
create mode 100644 api/index.js
create mode 100644 vercel.json
diff --git a/api/index.js b/api/index.js
new file mode 100644
index 0000000..4e90155
--- /dev/null
+++ b/api/index.js
@@ -0,0 +1,16 @@
+const app = require("express")();
+const axios = require("axios").default;
+const cors = require("cors");
+
+app.use(cors());
+
+app.get("/api/:query", async (req, res) => {
+ res.setHeader("Content-Type", "text/html");
+ res.setHeader("Cache-Control", "s-max-age=1, stale-while-revalidate");
+ const googleReq = await axios.get(
+ `https://suggestqueries.google.com/complete/search?client=chrome&q=${req.params.query}`
+ );
+ res.json(googleReq.data);
+});
+
+module.exports = app;
diff --git a/package.json b/package.json
index 0e569d8..10db88e 100644
--- a/package.json
+++ b/package.json
@@ -8,8 +8,11 @@
"@types/react-autosuggest": "^10.1.5",
"@types/react-dom": "^17.0.10",
"animejs": "^3.2.1",
+ "axios": "^0.24.0",
"bowser": "^2.11.0",
"boxicons": "^2.0.9",
+ "cors": "^2.8.5",
+ "express": "^4.17.1",
"react": "^17.0.2",
"react-autosuggest": "^10.1.0",
"react-dom": "^17.0.2",
diff --git a/public/index.html b/public/index.html
index 7e16334..9ab27ae 100644
--- a/public/index.html
+++ b/public/index.html
@@ -3,11 +3,11 @@
-
+
New Tab
-