fix gitignore
This commit is contained in:
parent
fefaea2bbd
commit
3b5718940f
4 changed files with 42 additions and 49 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -102,3 +102,5 @@ dist
|
|||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
src/temp
|
|
@ -8,6 +8,8 @@ import {
|
|||
} from "https://deno.land/std/fs/mod.ts";
|
||||
|
||||
const tempFolder = `${Deno.cwd()}/temp`;
|
||||
let weatherCache = "";
|
||||
let weatherTimeOut = new Date().getTime();
|
||||
|
||||
export async function startServer(): Promise<void> {
|
||||
// Create web server
|
||||
|
@ -16,36 +18,35 @@ export async function startServer(): Promise<void> {
|
|||
// Add resource folder
|
||||
app.use(serveStatic(tempFolder));
|
||||
|
||||
// Add route for index page
|
||||
app.get("/", (req, res) => {
|
||||
res.headers = new Headers({
|
||||
"content-type": "text/html; charset=UTF-8",
|
||||
});
|
||||
res.send(window.index);
|
||||
});
|
||||
|
||||
// Add route for weather
|
||||
app.get("/weather", async (req, res) => {
|
||||
const lat = "21.0425886";
|
||||
const lon = "105.8129389";
|
||||
const apiKey = "7b093bee7461b669e34c363d887cfdec";
|
||||
const response = await fetch(
|
||||
`https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&limit=1&appid=${apiKey}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
if (new Date().getTime() >= weatherTimeOut) {
|
||||
const lat = "21.0425886";
|
||||
const lon = "105.8129389";
|
||||
const apiKey = "7b093bee7461b669e34c363d887cfdec";
|
||||
const response = await fetch(
|
||||
`https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&limit=1&appid=${apiKey}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
res.send(response);
|
||||
);
|
||||
weatherCache = await response.json();
|
||||
weatherTimeOut = new Date().getTime() + 1800000;
|
||||
}
|
||||
res.send(weatherCache);
|
||||
});
|
||||
|
||||
// Minify all files and copy to temp folder
|
||||
await Compile();
|
||||
|
||||
// Start web server
|
||||
app.listen(7000, () =>
|
||||
console.log(
|
||||
`server has started on http://localhost:7000 🚀`,
|
||||
`Server has started on http://localhost:7000 🚀`,
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -58,7 +59,7 @@ export async function Compile(): Promise<void> {
|
|||
includeDirs: false,
|
||||
})
|
||||
) {
|
||||
console.log(entry.path);
|
||||
console.log("Minify: " + entry.path);
|
||||
let language = null;
|
||||
if (!entry.path.includes(".min.")) {
|
||||
if (entry.path.includes(".css")) {
|
||||
|
@ -89,30 +90,6 @@ export async function Compile(): Promise<void> {
|
|||
});
|
||||
}
|
||||
|
||||
export async function CompileIndex(): Promise<void> {
|
||||
//Read index.html content
|
||||
let indexPath = `${tempFolder}/index.html`;
|
||||
let indexContent = Deno.readTextFileSync(indexPath);
|
||||
|
||||
//Insert config into template
|
||||
// for (let property in window.config.website) {
|
||||
// indexContent = indexContent.replace(
|
||||
// `{{${property}}}`,
|
||||
// window.config.website[property],
|
||||
// );
|
||||
// }
|
||||
|
||||
//Insert localization into template
|
||||
// for (let key in window.language) {
|
||||
// indexContent = indexContent.replace(`{%${key}%}`, window.language[key]);
|
||||
// }
|
||||
|
||||
//Write index.html into temp folder
|
||||
//ensureDirSync(tempFolder);
|
||||
window.index = indexContent;
|
||||
//Deno.writeTextFileSync(`${tempFolder}/index.html`, indexContent);
|
||||
}
|
||||
|
||||
function changePath(path: string, from: string, to: string) {
|
||||
return Deno.cwd() + path.replace(Deno.cwd(), "").replace(from, to);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,14 @@ async function loadConfig() {
|
|||
|
||||
async function loadWeather() {
|
||||
// Get info from api
|
||||
const weather = { "coord": { "lon": 105.8129, "lat": 21.0426 }, "weather": [{ "id": 701, "main": "Mist", "description": "mist", "icon": "50n" }], "base": "stations", "main": { "temp": 297.14, "feels_like": 297.89, "temp_min": 297.14, "temp_max": 297.14, "pressure": 1008, "humidity": 88 }, "visibility": 4300, "wind": { "speed": 1.54, "deg": 30 }, "clouds": { "all": 100 }, "dt": 1648219888, "sys": { "type": 1, "id": 9308, "country": "VN", "sunrise": 1648162598, "sunset": 1648206535 }, "timezone": 25200, "id": 1581130, "name": "Hanoi", "cod": 200 };
|
||||
const response = await fetch(
|
||||
"/weather",
|
||||
{
|
||||
method: "GET",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
);
|
||||
const weather = await response.json();
|
||||
|
||||
// Parse weather id
|
||||
let icon = null;
|
||||
|
|
|
@ -10,7 +10,14 @@ async function loadConfig() {
|
|||
|
||||
async function loadWeather() {
|
||||
// Get info from api
|
||||
const weather = { "coord": { "lon": 105.8129, "lat": 21.0426 }, "weather": [{ "id": 701, "main": "Mist", "description": "mist", "icon": "50n" }], "base": "stations", "main": { "temp": 297.14, "feels_like": 297.89, "temp_min": 297.14, "temp_max": 297.14, "pressure": 1008, "humidity": 88 }, "visibility": 4300, "wind": { "speed": 1.54, "deg": 30 }, "clouds": { "all": 100 }, "dt": 1648219888, "sys": { "type": 1, "id": 9308, "country": "VN", "sunrise": 1648162598, "sunset": 1648206535 }, "timezone": 25200, "id": 1581130, "name": "Hanoi", "cod": 200 };
|
||||
const response = await fetch(
|
||||
"/weather",
|
||||
{
|
||||
method: "GET",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
);
|
||||
const weather = await response.json();
|
||||
|
||||
// Parse weather id
|
||||
let icon = null;
|
||||
|
|
Loading…
Add table
Reference in a new issue