Yeah, you can implement this in-house for your needs in less then 30 minutes using 512mb DO droplet or other in-house devops tool server for free.
Basically:
1. sign up for droplet 10 min
2. install google-chrome and webserver 10 min
3. call google headless from a CGI script 10 min const express = require('express')
const app = express()
const puppeteer = require('puppeteer')
const uuidv1 = require('uuid/v1')
const fs = require('fs')
const validUrl = require('valid-url')
app.get('/', function (req, res) {
(async () => {
const url = req.query.url;
if (!url) {
return res.send({error: 'Need to specify url param e.g. ?url=https://google.com/'});
}
if (!validUrl.isUri(url)) { // Also protects against file://...
return res.send({error: 'url not valid'})
}
const id = uuidv1();
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setViewport({ width: 1920, height: 1080})
await page.goto(url)
const buffer = await page.screenshot({path: id + '.png'})
const fullPath = __dirname + '/' + id + '.png';
res.sendFile(fullPath, function () {
fs.unlink(fullPath)
})
await browser.close()
})();
})
app.listen(3000, function () {
console.log('Example app listening on port 3000!')
}) if (!validUrl.isUri(url)) { // Also protects against file://...
It does? ▶ cat valid.js
var validUrl = require('valid-url');
if (validUrl.isUri("file:///etc/passwd")){
console.log('Looks like a URI');
}
▶ node valid.js
Looks like a URI
Perhaps the problem requires a little more than 15 minutes to do well :)In fact, the two are often inversely correlated because engineers can be so worried about what technology, what stack, what language, instead of worrying about the real deal: getting the users.
IMO there should be a line of what to outsource and what to build yourself. In my mind simple things like this go into second category.
So assuming a rate of $80/hr (which is on the low-side), it cost you $20 in time to do what you could have for $7.
A CTO worth 500k/year would probably realise that paying $7 is more cost effective.