1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import sass from "npm:sass";
export default async function(req: Request): Promise<Response> {
if (req.method !== "POST") {
return Response.json({ error: "This val responds to POST requests." }, {
status: 400,
});
}
const body = await req.json();
if (!body.sass) {
return Response.json({ error: "No Sass" }, {
status: 400,
});
}
try {
return Response.json({
css: sass.compileString(body.sass).css.toString(),
});
} catch (err) {
return Response.json({ error: err.message }, {
status: 400,
});
}
}