Skip to content

Commit

Permalink
🐛 Use correct config file (fixed upptime/upptime#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Oct 28, 2020
1 parent 6d12e7c commit 50fb197
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/server.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import * as sapper from "@sapper/server";
import compression from "compression";
import fs from "fs";
import fs from "fs-extra";
import polka from "polka";
import sirv from "sirv";
import { safeLoad } from "js-yaml";

const { PORT, NODE_ENV } = process.env;
const dev = NODE_ENV === "development";
const configFile = safeLoad(fs.readFileSync(".upptimerc.yml", "utf8"));

let config = safeLoad(fs.readFileSync(join(".", ".upptimerc.yml"), "utf8"));
try {
const file = fs.readFileSync(join("..", "..", ".upptimerc.yml"), "utf8");
if (file) {
config = safeLoad(file);
console.log("Using root config instead", config);
}
} catch (error) {
console.log("Root config not found 2 dirs up");
}
const baseUrl = (config["status-website"] || {}).baseUrl || "/";

polka()
.use(
(configFile || {})["status-website"].baseUrl || "/",
compression({ threshold: 0 }),
sirv("static", { dev }),
sapper.middleware()
)
.use(baseUrl, compression({ threshold: 0 }), sirv("static", { dev }), sapper.middleware())
.listen(PORT, (err) => {
if (err) console.log("error", err);
});

0 comments on commit 50fb197

Please sign in to comment.