mirror of
https://github.com/Galax028/startpage.git
synced 2024-11-21 22:53:08 +01:00
Added CORS proxy serverless
This commit is contained in:
parent
6b21925bf2
commit
a8faeb2d83
16
api/index.js
Normal file
16
api/index.js
Normal file
@ -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;
|
@ -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",
|
||||
|
@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="description" content="A Customizable Startpage" />
|
||||
<meta name="description" content="A Customizable Startpage." />
|
||||
<title>New Tab</title>
|
||||
</head>
|
||||
<body>
|
||||
|
@ -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];
|
||||
|
3
vercel.json
Normal file
3
vercel.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"rewrites": [{ "source": "/api/(.*)", "destination": "/api" }]
|
||||
}
|
Loading…
Reference in New Issue
Block a user