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
- + diff --git a/src/components/ts/Search.tsx b/src/components/ts/Search.tsx index 2ef2972..e4f4658 100644 --- a/src/components/ts/Search.tsx +++ b/src/components/ts/Search.tsx @@ -17,12 +17,7 @@ class Search extends Component { }; onSuggestionsFetchRequested = ({ value }) => { - fetch( - `https://thingproxy.freeboard.io/fetch/https://suggestqueries.google.com/complete/search?client=chrome&q=${value.replace( - " ", - "_" - )}` - ) + fetch(`/api/${value.replace(" ", "_")}`) .then((res) => res.json()) .then((data) => { const newSuggestions: string[] = data[1]; diff --git a/vercel.json b/vercel.json new file mode 100644 index 0000000..06d93d5 --- /dev/null +++ b/vercel.json @@ -0,0 +1,3 @@ +{ + "rewrites": [{ "source": "/api/(.*)", "destination": "/api" }] +}