Last active
December 9, 2020 18:48
-
-
Save yakirp/b121d110f7ea0dfc6a46ac924d21149e to your computer and use it in GitHub Desktop.
Chess Image Generator Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const functions = require('firebase-functions'); | |
var ChessImageGenerator = require('chess-image-generator'); | |
const express = require('express'); | |
var bodyParser = require('body-parser') | |
var decode = require('urldecode') | |
const app = express(); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({ | |
extended: true | |
})); | |
app.get('/*', (request, response) => { | |
var imageGenerator = new ChessImageGenerator({ | |
size: 1024, | |
style: 'merida' | |
}) | |
imageGenerator.loadFEN(decode(request.url.substring(1))); | |
imageGenerator.generateBuffer() | |
.then(function (buffer) { | |
response.setHeader("Content-Type", "image/png") | |
response.status(200).send(buffer) | |
}, function (err) { | |
response.status(400).send(err) | |
}); | |
}); | |
exports.chess = functions.https.onRequest(app); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment