mirror of
https://github.com/Galax028/startpage.git
synced 2025-01-24 09:08:34 +01:00
Make proxy compatible with vercel
This commit is contained in:
parent
51e4ee43a1
commit
636cad4ed4
19
cors.py
19
cors.py
@ -1,19 +0,0 @@
|
||||
import requests
|
||||
from flask import Flask, jsonify
|
||||
|
||||
cors = Flask(__name__)
|
||||
|
||||
|
||||
@cors.get("/<string:query>")
|
||||
def deal_with_cors(query):
|
||||
return {"data": requests.get(f"https://ac.duckduckgo.com/ac/?q={query}&type=list").json()[1]}
|
||||
|
||||
|
||||
@cors.after_request
|
||||
def actually_deal_with_cors(res):
|
||||
res.headers["Access-Control-Allow-Origin"] = "*"
|
||||
return res
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
cors.run("localhost", 8080)
|
6
main.js
6
main.js
@ -44,7 +44,7 @@ $(() => {
|
||||
$("#greeting").text(`Good ${new Date().getHours() < 12 ? "morning" : new Date().getHours() < 18 ? "afternoon" : "evening"}, ${conf.username}.`);
|
||||
|
||||
// Weather Detection
|
||||
/* if (navigator.geolocation) {
|
||||
if (navigator.geolocation) {
|
||||
navigator.geolocation.getCurrentPosition((pos) => {
|
||||
$.get(`https://api.openweathermap.org/data/2.5/onecall?lat=${pos.coords.latitude}&lon=${pos.coords.longitude}&units=${conf.weather.unit}&appid=${conf.weather.apikey}`, (res) => {
|
||||
let ress = res.current;
|
||||
@ -75,7 +75,7 @@ $(() => {
|
||||
}
|
||||
});
|
||||
});
|
||||
} */
|
||||
}
|
||||
|
||||
// Search
|
||||
$("#search").on("keyup", (event) => {
|
||||
@ -89,7 +89,7 @@ $(() => {
|
||||
}
|
||||
} else if (event.key === " " && event.ctrlKey) {
|
||||
if ($("#search").val().length === 0 || !$("#search").val().trim()) { } else {
|
||||
$.get(`http://localhost:8080/${$("#search").val()}`, (res) => {
|
||||
$.get(`/ac/${$("#search").val()}`, (res) => {
|
||||
$(".search-predictions > ul").remove();
|
||||
res = res.data.slice(0, 10);
|
||||
var predictions = "<ul>";
|
||||
|
23
proxy.py
Normal file
23
proxy.py
Normal file
@ -0,0 +1,23 @@
|
||||
import requests
|
||||
from flask import Flask, send_from_directory
|
||||
|
||||
server = Flask(__name__)
|
||||
|
||||
|
||||
@server.get("/<string:file>")
|
||||
def startpage(file = None):
|
||||
if not file:
|
||||
return send_from_directory("/", "startpage.html")
|
||||
else:
|
||||
return send_from_directory("/", file)
|
||||
|
||||
|
||||
@server.get("/ac/<string:query>")
|
||||
def deal_with_cors(query):
|
||||
return {"data": requests.get(f"https://ac.duckduckgo.com/ac/?q={query}&type=list").json()[1]}
|
||||
|
||||
|
||||
@server.after_request
|
||||
def actually_deal_with_cors(res):
|
||||
res.headers["Access-Control-Allow-Origin"] = "startpage.galax.tech"
|
||||
return res
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
flask==2.0.0rc2
|
||||
requests==2.25.1
|
@ -5,7 +5,7 @@
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link rel="stylesheet" href="./styles.css" />
|
||||
<link rel="stylesheet" href="/styles.css" />
|
||||
<link rel="shortcut icon" type="image/x-icon">
|
||||
<title>New Tab</title>
|
||||
</head>
|
||||
@ -38,7 +38,7 @@
|
||||
crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/bowser/2.11.0/bundled.js" referrerpolicy="no-referrer"
|
||||
crossorigin="anonymous"></script>
|
||||
<script src="./main.js"></script>
|
||||
<script src="/main.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
15
vercel.json
Normal file
15
vercel.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"version": 2,
|
||||
"builds": [
|
||||
{
|
||||
"src": "./proxy.py",
|
||||
"use": "@vercel/python"
|
||||
}
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"src": "./",
|
||||
"dest": "./"
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user