-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.ts
55 lines (48 loc) · 1.64 KB
/
server.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
53
54
55
import { Application, Router } from "https://deno.land/x/oak/mod.ts";
import config from "./config.ts";
import {
createAccount,
createWebhook,
deleteAccount,
deleteWebhook,
getAccount,
updateAccountInfo,
verifyAccount,
} from "./routers/account.ts";
import { checkConsent, receive, send } from "./routers/message.ts";
// Get command line argument that specifiys the port number.
if (
(Deno.args[0] != null) && (Deno.args[0] !== "") &&
!isNaN(Number(Deno.args[0].toString()))
) {
config.PORT = +Deno.args[0];
} else {
throw "Please specify a port";
}
const app = new Application();
const indexRouter = new Router();
const accountsRouter = new Router();
const messagesRouter = new Router();
indexRouter.get("/", (ctx) => {
ctx.response.body = "Hello from Signal-CLI-API ";
});
accountsRouter
.get("/accounts/:number", getAccount)
.post("/accounts/:number", createAccount)
.patch("/accounts/:number", updateAccountInfo)
.patch("/accounts/:number/verify", verifyAccount)
.delete("/accounts/:number", deleteAccount)
.post("/accounts/:number/webhook", createWebhook)
.delete("/accounts/:number/webhook", deleteWebhook);
messagesRouter
.get("/messages/:number", receive)
.post("/messages/:number", send)
.post("/messages/consent/:number", checkConsent);
app.use(messagesRouter.routes());
app.use(messagesRouter.allowedMethods());
app.use(accountsRouter.routes());
app.use(accountsRouter.allowedMethods());
app.use(indexRouter.routes());
app.use(indexRouter.allowedMethods());
app.listen({ port: config.PORT });
console.log(`Server is running on <http://localhost:${config.PORT}/>`);