-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
28 lines (23 loc) · 773 Bytes
/
utils.js
File metadata and controls
28 lines (23 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
export function getBaseURL() {
let baseUrl = process.env.PROJECT_DOMAIN || "";
if (!baseUrl.startsWith("http")) baseUrl = `https://${baseUrl}.glitch.me`;
if (baseUrl.startsWith("https://.glitch")) throw new Error("The project domain is not set, please set it in the .env file");
return baseUrl;
}
/**
*
* @param {Response} res
* @param {Number} err
* @param {String} message
*/
export function handleErrors(res, err, message) {
res.status(err).send({
code: err,
message
});
}
export function formatMS(ms) {
let tmp = new Date(ms)
const fixNum = (n) => String(n).length == 1 ? '0' + n : n;
return `${tmp.getUTCHours() > 0 ? `${tmp.getUTCHours()}:` : ''}${fixNum(tmp.getMinutes())}:${fixNum(tmp.getSeconds())}`;
}