-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ts
59 lines (53 loc) · 2.12 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
56
57
58
59
import { Application } from "https://deno.land/x/oak/mod.ts";
import { DenoRouter } from "./routes/deno.routes.ts";
import { ExtendUserController } from "./controllers/extendUserController.ts";
import { userCollection, bookCollection, authorCollection } from "./db/_db.ts";
import { UserSchema } from "./schemas/user.schema.ts";
import { UserOut } from "./dtos/outputs/userOut.model.ts";
import { UserInputSchema } from "./dtos/inputs/userInput.model.ts";
import { BookController } from "./controllers/bookController.ts";
import { BookSchema } from "./schemas/book.schema.ts";
import { BookOut } from "./dtos/outputs/bookOut.model.ts";
import { BookInputSchema } from "./dtos/inputs/bookInput.model.ts";
import { AuthorController } from "./controllers/authorController.ts";
import { AuthorSchema } from "./schemas/author.schema.ts";
import { AuthorOut } from "./dtos/outputs/authorOut.model.ts";
import { AuthorInputSchema } from "./dtos/inputs/authorInput.model.ts";
const port = Deno.env.get('PORT') || 5000;
const app = new Application();
let denoRouter = new DenoRouter(
[
{
controller: new ExtendUserController(userCollection, UserSchema, UserOut, UserInputSchema),
methods: {
get: true,
getForFind: 'find',
post: 'add'
},
name: '',
path: '/api/v1/users'
}, {
controller: new BookController(bookCollection, BookSchema, BookOut, BookInputSchema),
methods: {
get: 'getAll',
getForFind: 'find',
post: 'add'
},
name: '',
path: '/api/v1/books'
}, {
controller: new AuthorController(authorCollection, AuthorSchema, AuthorOut, AuthorInputSchema),
methods: {
get: true,
getForFind: true,
post: true
},
name: '',
path: '/api/v1/authors'
}
]
);
app.use(denoRouter.router.routes());
app.use(denoRouter.router.allowedMethods());
console.log(`server running on port ${port}`);
await app.listen({ port: +port });