Add handler

This commit is contained in:
Steven 2019-01-21 11:07:12 -05:00
parent 542616a74a
commit a0a1e93f68
3 changed files with 13 additions and 3 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
node_modules
package-lock.json
package-lock.json
dev.html

11
card.js
View File

@ -3,7 +3,7 @@ const { getScreenshot } = require('./chromium');
const { getHtml } = require('./template');
const { writeTempFile, pathToFileURL } = require('./file');
module.exports = async function (req, res) {
async function handler(req, res) {
try {
let {
type = 'png',
@ -28,3 +28,12 @@ module.exports = async function (req, res) {
}
};
if (!process.env.NOW_REGION) {
const { createServer } = require('http');
const PORT = process.env.PORT || 3000;
const listen = () => console.log(`Listening on ${PORT}...`);
createServer(handler).listen(PORT, listen);
}
module.exports = handler;

View File

@ -4,7 +4,7 @@
"description": "Generate an open graph image for twitter/facebook/etc",
"main": "card.js",
"scripts": {
"dev": "node dev.js"
"start": "node card.js"
},
"author": "styfle",
"repository": "github:styfle/og-image",