1
0
mirror of https://github.com/osmarks/random-stuff synced 2024-11-09 22:09:55 +00:00
random-stuff/luamin-api.js

30 lines
617 B
JavaScript
Raw Normal View History

2020-08-12 19:31:12 +00:00
const express = require("express")
const luamin = require("luamin")
const app = express()
app.use(function(req, res, next) {
var data = ''
req.setEncoding('utf8')
req.on('data', chunk => {
data += chunk
})
req.on('end', () => {
req.body = data
next()
})
});
app.post("*", (req, res) => {
console.log("Input length:", req.body.length)
try {
const min = luamin.minify(req.body)
console.log("Output length:", min.length)
res.send(min)
} catch(e) {
res.status(400).send(e.toString())
}
res.end()
})
app.listen(12432)