-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
33 lines (26 loc) · 939 Bytes
/
index.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
const express = require('express');
// Import math utils
const math_utils_add = require('./math-utils/math_utils_add');
const math_utils_pow = require('./math-utils/math_utils_pow');
// Import swagger
const swaggerUi = require('swagger-ui-express');
const swaggerJsDoc = require('swagger-jsdoc');
const swaggerConfig = require('./swagger-config');
const app = express();
app.use(express.json());
// Swagger setup
const specs = swaggerJsDoc(swaggerConfig);
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(specs));
// Start the server
app.listen(3000, () => {
console.log('Server is running on port 3000');
});
// REQUEST HANDLERS
// Endpoint that adds two numbers
app.get('/add', (req, res) => {
res.send(math_utils_add(req.query.a, req.query.b).toString());
});
// Endpoint that raises one number to the power of another
app.get('/pow', (req, res) => {
res.send(math_utils_pow(req.query.a, req.query.b).toString());
});