-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
40 lines (26 loc) · 922 Bytes
/
app.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
const express = require('express');
const app = express();
const Converter = require('./Converter');
const validate = require('./validate');
app.use(express.json())
app.post('/rgb' , (req, res) => {
const { code } = req.body;
const len = validate.length(code)
if(!len) res.status(400).send({err: "Too long"})
const format = validate.format(code)
if(!format) res.status(400).send({err: "Incorrect"})
const color = new Converter(code);
const hex = color.toHex();
res.status(200).send({ hex })
})
app.post('/hex', (req, res) => {
const { code } = req.body;
const len = validate.length(code)
if(!len) res.status(400).send({err: "Too long"})
const format = validate.format(code)
if(!format) res.status(400).send({ err: "Incorrect"})
const color = new Converter(code)
const rgb = color.toRgb()
res.status(200).send({rgb})
})
module.exports = app;