-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.ts
52 lines (49 loc) · 1.56 KB
/
mod.ts
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
47
48
49
50
51
52
import { opine } from "https://deno.land/x/[email protected]/mod.ts";
import * as log from "https://deno.land/[email protected]/log/mod.ts";
import GlobalRoutes from "./src/routes/GlobalRoutes.ts";
import registerHandlebars from "./src/handlerbars/Init.ts";
import { Protocols } from "./src/models/CamouflageModels.ts";
export class CamouflageServer {
start = async (
loglevel: string,
httpEnable: boolean,
httpPort: number,
httpMocksDir: string,
httpsEnable: boolean,
httpsPort: number,
cert: string,
key: string
) => {
await log.setup({
handlers: {
console: new log.handlers.ConsoleHandler(setLogLevel(loglevel), {
formatter: "{levelName} {msg}",
}),
},
});
const logger = log.getLogger();
const app = opine();
registerHandlebars(logger);
const globalRoutes: GlobalRoutes = new GlobalRoutes(app, httpMocksDir, logger);
globalRoutes.defineGlobalRoutes();
if (httpEnable) {
logger.info(`HTTP Server started at http://localhost:${httpPort}`);
app.listen({ port: httpPort });
}
if (httpsEnable) {
logger.info(`HTTP Server started at https://localhost:${httpsPort}`);
app.listen({
port: httpsPort,
certFile: cert,
keyFile: key,
});
}
};
}
export function setLogLevel(loglevel: string): "NOTSET" | "DEBUG" | "INFO" | "WARNING" | "ERROR" | "CRITICAL" {
return <"NOTSET" | "DEBUG" | "INFO" | "WARNING" | "ERROR" | "CRITICAL">loglevel.toUpperCase();
}
export interface CamouflageConfig {
loglevel: string;
protocols: Protocols;
}