-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
46 lines (41 loc) · 1.27 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
import express from 'express';
import bodyParser from 'body-parser';
import cors from 'cors';
import path from 'path';
import {
appPort,
staticPath
} from './etc/config.json';
import ImageGenerator, {evaluateFunc} from './imageGenerator';
const app = express();
console.log(`IMAGE GENERATOR STARTING AT PORT ${appPort}`);
const config = {
templatePath : path.join(staticPath, 'templates', 'index.html'),
destinationPath : path.join(staticPath, 'memes', `test.png`)
};
const templateWidth = 1152;
const templateHeight = 768;
app.use(bodyParser.json({ limit : 1024 * 1024,
verify : (req, res, buf) => {
try {
JSON.parse(buf);
} catch (e) {
res.send({
status : 0,
error : {
code : 'BROKEN_JSON',
message : 'Please, verify your json'
}
});
}
}
}));
app.use(cors({ origin: '*' }));
app.use('/static', express.static(staticPath));
app.post('/generate', async (req, res) => {
const { texts, zoom } = req.body;
const generator = new ImageGenerator();
await generator.generate(templateWidth, templateHeight, {...config, texts}, evaluateFunc, zoom)
res.sendStatus(200);
});
app.listen(appPort);