-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
96 lines (72 loc) · 2.65 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const express = require('express');
const fs = require('fs'); // Import the fs module
const crypto = require('crypto');
const jwt = require('jsonwebtoken');
const app = express();
// Configure built-in body-parser with a larger limit
app.use(express.json({ limit: '50mb' }));
app.use(express.urlencoded({ limit: '50mb', extended: true }));
const port = 5050;
app.listen(port, () => {
console.log(`Server running on port ${port}`);
});
app.get('/token', (req, res) => {
try {
const token = req.query.token;
if (!token) {
return res.status(400).send('Token not found');
}
// decode Token
const decoded = jwt.decode(token, { complete: true });
const storedValuesJson = JSON.parse(decoded.payload.stored_values);
if (!decoded) {
return res.status(400).send('Invalid Token');
}
if (storedValuesJson && Array.isArray(storedValuesJson)) {
console.log('Recorriendo stored_values:');
storedValuesJson.forEach(item => {
console.log(`Pointer: ${item.pointer}`);
console.log(`Value: ${JSON.stringify(item.value)}`);
});
}
res.status(201).send({
message: 'Decoded token',
decodedToken: decoded
});
} catch (err) {
console.error('Error in /token:', err);
res.status(500).send('Error processing token');
}
});
app.get('/tokenxx', (req, res) => {
console.log(req.body);
// Convert req.body to a JSON string
const data = JSON.stringify(req.body, null, 2);
// Generate a random file name
const randomFileName = `requestData_${crypto.randomUUID()}.json`;
// Write the JSON to a file with a random name
fs.writeFile(randomFileName, data, { flag: 'a+' }, err => {
if (err) {
console.error(err);
return res.status(500).send('An error occurred on the server.'); // Send a 500 error if writing fails
}
// Send success response if everything went well
res.status(201).send('User created and data logged');
});
});
app.get('/tokenxx', (req, res) => {
console.log(req.body);
// Convert req.body to a JSON string
const data = JSON.stringify(req.body, null, 2);
// Generate a random file name
const randomFileName = `requestData_${crypto.randomUUID()}.json`;
// Write the JSON to a file with a random name
fs.writeFile(randomFileName, data, { flag: 'a+' }, err => {
if (err) {
console.error(err);
return res.status(500).send('An error occurred on the server.'); // Send a 500 error if writing fails
}
// Send success response if everything went well
res.status(201).send('User created and data logged');
});
});