-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Romain Barissat <[email protected]>
- Loading branch information
1 parent
8cae852
commit 72c1e22
Showing
6 changed files
with
798 additions
and
28 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
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,20 +1,26 @@ | ||
const { settings } = require("./settings"); | ||
const express = require("express"); | ||
const yaml = require("js-yaml"); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const expressMeter = require("./observability/meter"); | ||
const { expressLogger, logger } = require("./observability/logger"); | ||
|
||
try { | ||
const settings = yaml.load( | ||
fs.readFileSync(path.join(__dirname, "config/settings.yaml"), "utf8") | ||
); | ||
|
||
const port = process.env.PORT || settings.general.defaultPort || 3000; | ||
|
||
const app = express(); | ||
app.get("/", (req, res) => | ||
res.send(`Hello ${settings.general.welcomeName}!`) | ||
); | ||
app.listen(port, () => console.log(`App listening on port ${port}!`)); | ||
|
||
app.use(expressLogger); | ||
app.use(expressMeter); | ||
|
||
app.get("/", (req, res) => { | ||
req.log.info("Visited homepage"); | ||
req.log.error("Example error"); | ||
req.log.debug("Example debug"); | ||
req.log.trace("Example trace"); | ||
res.send(`Hello ${settings.general.welcomeName}!`); | ||
}); | ||
|
||
app.listen(port, () => { | ||
logger.info(`App listening on port ${port}!`); | ||
}); | ||
} catch (e) { | ||
console.error(e); | ||
logger.error(e); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const expressLogger = require("pino-http")(); | ||
|
||
const logger = expressLogger.logger; | ||
logger.level = process.env.LOG_LEVEL || "info"; | ||
|
||
module.exports = { expressLogger, logger }; |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const express = require("express"); | ||
const prometheus = require("prom-client"); | ||
|
||
const register = new prometheus.Registry(); | ||
prometheus.collectDefaultMetrics({ register }); | ||
|
||
const router = express.Router(); | ||
router.get("/metrics", async (req, res) => { | ||
try { | ||
res.set("Content-Type", register.contentType); | ||
res.end(await register.metrics()); | ||
} catch (e) { | ||
req.log.error(e); | ||
res.status(500).end(e); | ||
} | ||
}); | ||
|
||
module.exports = router; |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const yaml = require("js-yaml"); | ||
const { logger } = require("./observability/logger"); | ||
|
||
try { | ||
const settings = yaml.load( | ||
fs.readFileSync(path.join(__dirname, "config/settings.yaml"), "utf8") | ||
); | ||
exports.settings = settings; | ||
} catch (e) { | ||
logger.error(e); | ||
} |
Oops, something went wrong.