Skip to content

Commit

Permalink
replace http-Error library
Browse files Browse the repository at this point in the history
  • Loading branch information
hmt committed Nov 18, 2021
1 parent 457b47a commit 60b1260
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Then create a `servers.json` file like this here:
Now you are ready to start the script. Make sure to have an environment variable
called `TINYSCALE_SECRET`:

TINYSCALE_SECRET=some_secret_string deno run --allow-net --allow-read --allow-env https://deno.land/x/tinyscale@v1.6.4/mod.ts
TINYSCALE_SECRET=some_secret_string deno run --allow-net --allow-read --allow-env https://deno.land/x/tinyscale@v1.7.0/mod.ts

tinyscale will then run on port 3005 and you will have to set up your reverse
proxy so that it can pick up requests. If you prefer a different port you can
Expand Down
11 changes: 6 additions & 5 deletions app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { opine, ErrorRequestHandler, Router, secret, createError, Color, deferred, Deferred } from "./deps.ts";
import { opine, ErrorRequestHandler, Router, secret, HttpError, Color, deferred, Deferred } from "./deps.ts";
import { BBB } from './bbb.ts';
import { Servers, server } from './servers.ts'
import { Servers } from './servers.ts'
import type { server } from './deps.ts'

const date = () => new Date().toLocaleTimeString('de')

Expand All @@ -22,7 +23,7 @@ router.use("/:call", (req, res, next) => {
res.locals.handler = handler
next()
} else {
next(createError(401))
next(new HttpError(401));
}
})
// if the param is call, check for races
Expand Down Expand Up @@ -62,7 +63,7 @@ router.all("/:call", async (req, res, next) => {
res.send(body)
} catch (e) {
if (handler.call === 'create') { queue[handler.meeting_id]?.resolve(e); delete queue[handler.meeting_id] }
next(createError(500))
next(new HttpError(500));
}
}
console.log(res.locals.log.join(' '));
Expand All @@ -80,7 +81,7 @@ const errorHandler: ErrorRequestHandler = (err, req, res, next) => {

const app = opine()
.use("/bigbluebutton/api", router)
.use((req, res, next) => next(createError(404)))
.use((req, res, next) => next(new HttpError(404)))
.use(errorHandler);

export default app;
2 changes: 1 addition & 1 deletion bbb.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Request, ParamsDictionary, createHash } from "./deps.ts";
import type { server } from './deps.ts'

export interface server { host: string; secret: string };
export class BBB {
call: string
checksum_incoming: string
Expand Down
9 changes: 5 additions & 4 deletions deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ export type { Deferred } from "https://deno.land/std/async/mod.ts";
export { join } from "https://deno.land/std/path/mod.ts";
export { createHash } from "https://deno.land/std/hash/mod.ts";
export * as Color from "https://deno.land/std/fmt/colors.ts";
export { createError } from "https://deno.land/x/http_errors@3.0.0/mod.ts";
export { opine, Router } from "https://deno.land/x/opine@1.7.2/mod.ts";
export type { ErrorRequestHandler, Request, ParamsDictionary } from "https://deno.land/x/opine@1.7.2/mod.ts";
export const secret: string = Deno.env.get("TINYSCALE_SECRET") || ""
export { HttpError } from "https://deno.land/x/http_error@0.1.2/mod.ts";
export { opine, Router } from "https://deno.land/x/opine@1.9.1/mod.ts";
export type { ErrorRequestHandler, Request, ParamsDictionary } from "https://deno.land/x/opine@1.9.1/mod.ts";
export const secret: string = Deno.env.get("TINYSCALE_SECRET") || ""
export interface server { host: string; secret: string };
5 changes: 2 additions & 3 deletions servers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createHash, Color } from "./deps.ts";
export interface server { host: string; secret: string };

import type { server } from './deps.ts'
export class Servers {
servers: server[]
iterator!: IterableIterator<server>
Expand Down Expand Up @@ -36,7 +35,7 @@ export class Servers {
if (!ok) throw "Configuration error. Exiting …"
} catch (e) {
// exit tinyscale if an error is encountered in servers.json
console.log(Color.brightRed(e))
console.log(Color.brightRed(JSON.stringify(e)))
Deno.exit(1);
}
})
Expand Down

0 comments on commit 60b1260

Please sign in to comment.