-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstants.js
46 lines (40 loc) · 1.15 KB
/
constants.js
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const express = require('express');
const logger = require('./logger');
/**
* You can change these freely, these are just the default
*/
const constants = {
toursLoc: __dirname + "/tours/",
tempLoc: __dirname + "/temp/",
logPath: __dirname + "/log/editour.log",
/**
* returns a string of random numbers and letters, n characters long
* @param {number} n length of the random string
* @return {string} a random string
*/
randName: (n) => {
const l = "1234567890abcdefghijklmnopqrstuvwxyz";
let out = "";
for (let i = 0; i < n; ++i) {
out += l[Math.floor(Math.random() * 36)];
}
return out;
},
/**
* Logs an error, then sends it to the client with a specified status code
* and message
* @param {express.Response} res response object to send to
* @param {number} code HTTP status code, e.g. 404
* @param {string} message message to send
*/
returnError: (res, code, message) => {
logger.error(message);
res.status(code).header("Content-type", "application/json").send(
JSON.stringify({
status: code,
message: message
})
);
}
};
module.exports = constants;