generated from pabio/template
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Use correct config file (fixed upptime/upptime#40)
- Loading branch information
1 parent
6d12e7c
commit 50fb197
Showing
1 changed file
with
14 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |