-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
47 lines (33 loc) · 1.21 KB
/
server.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
47
import Fastify from "fastify";
import controllers from './src/api/controllers';
import errors from "./src/infra/errors";
const port = process.env.PORT;
const server = Fastify({ logger: true });
server.post('/api/auction.create', req => {
const response = controllers.auction.create(req);
return response;
});
server.post('/api/bidder.create', req => {
const response = controllers.bidder.create(req);
return response;
});
server.post('/api/bid.add', req => {
const response = controllers.bid.add(req);
return response;
});
server.post('/api/auction.knock', req => {
const response = controllers.auction.knock(req);
return response;
});
server.setErrorHandler((err, req, res) => {
const problem = errors.handle(err);
res.status(problem.status).send(problem);
});
server.setNotFoundHandler((req, res) => {
const err = new errors.AppError(errors.ErrorType.NotFound, 'The requested resource was not found', 'The requested resource was not found', true);
const problem = errors.handle(err);
res.status(problem.status).send(problem);
});
server.listen(port)
.then(address => console.log(`Applications is listening on port ${address}`))
.catch(err => console.log('Error starting the server:', err));