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 @@
- +