-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
49 lines (41 loc) · 1.32 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
const express = require('express');
const dotenv = require('dotenv');
const bodyParser = require('body-parser');
const createImage = require('./utils/createImage');
const uploadToIPFS = require('./utils/uploadToIPFS');
const generateSignature = require('./utils/generateSignature');
dotenv.config();
if (!process.env.SIGNER_WALLET_PRIVATE_KEY || !process.env.INFURA_PROJECT_ID) {
console.error(
'Please set SIGNER_WALLET_PRIVATE_KEY and INFURA_PROJECT_ID environment variables.'
);
process.exit(1);
}
const app = express();
app.use(bodyParser.json());
app.get('/', (req, res) => {
res.send('Hello World!!!');
});
app.post('/mint', async (req, res) => {
// TODO add request JSON validation
const pfp = req.body.pfp;
const enableLaser = req.body.enableLaser;
console.log('Received a new request with pfp: ', pfp);
try {
const imageDataUrl = await createImage(pfp, enableLaser);
const imageIPFSURI = await uploadToIPFS(imageDataUrl);
const signature = await generateSignature(imageIPFSURI);
res.json({
success: true,
image: imageDataUrl,
imageIPFSURI: imageIPFSURI,
signature: signature,
});
} catch (err) {
res.json({
success: false,
errorMessage: err.message,
});
}
});
app.listen(process.env.PORT || 3100, () => console.log('Server is running...'));