stacker.news/pages/api/capture/[[...path]].js

17 lines
427 B
JavaScript
Raw Normal View History

2021-07-08 00:15:27 +00:00
import Pageres from 'pageres'
import path from 'path'
export default async function handler (req, res) {
2021-07-08 00:45:02 +00:00
const url = process.env.SELF_URL + '/' + path.join(...(req.query.path || []))
2021-07-08 00:15:27 +00:00
res.setHeader('Content-Type', 'image/png')
try {
const streams = await new Pageres({ crop: true })
2021-07-08 00:15:27 +00:00
.src(url, ['600x300'])
.run()
res.status(200).end(streams[0])
} catch(e) {
console.log(e)
res.status(500)
}
2021-07-08 00:15:27 +00:00
}