-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (27 loc) · 800 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
34
require('dotenv').config();
const express = require('express');
const bodyParser = require('body-parser');
const {
encryptData
} = require('./utils');
const app = express();
const port = process.env.PORT || 3000;
app.use(bodyParser.json());
app.post('/encrypt', async (req, res) => {
try {
const { dataToEncrypt } = req.body;
if (!dataToEncrypt) {
return res.status(400).json({ error: 'No data provided for encryption' });
}
const encryptedData = await encryptData(dataToEncrypt);
res.json({ encryptedData });
} catch (error) {
res.status(500).json({ error: 'Encryption failed', details: error.message });
}
});
app.get('/', (req, res) => {
res.status(200).send('OK');
});
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});