1- import postcss , { type CssSyntaxError } from "postcss" ;
1+ import postcss from "postcss" ;
22import tailwindcss from "tailwindcss" ;
33import autoprefixer from "autoprefixer" ;
4- import { NextApiRequest , NextApiResponse } from "next" ;
54import cssbeautify from "cssbeautify" ;
65
6+ import type { NextApiRequest , NextApiResponse } from "next" ;
7+ import type { ProcessOptions , CssSyntaxError } from "postcss" ;
8+
79interface RequestBody {
810 classes : string ;
911}
@@ -15,6 +17,8 @@ const processor = postcss([
1517 autoprefixer ,
1618] ) ;
1719
20+ const processOptions : ProcessOptions = { from : undefined } ;
21+
1822const beautifyOptions : Parameters < typeof cssbeautify > [ 1 ] = {
1923 indent : " " ,
2024 openbrace : "end-of-line" ,
@@ -35,7 +39,7 @@ export default async function handler(
3539 const css = `.generated { @apply ${ classes . join ( " " ) } ; }` ;
3640
3741 let result = await processor
38- . process ( css , { from : undefined } )
42+ . process ( css , processOptions )
3943 . then ( ( result ) => result . css ) ;
4044
4145 if ( customClasses . length ) {
@@ -62,13 +66,17 @@ export default async function handler(
6266
6367 //
6468 } else {
65- res . status ( 500 ) . send ( error . toString ( ) ) ;
69+ res
70+ . status ( 200 )
71+ . send ( error . reason || error . toString ( ) || "500 Server Error" ) ;
6672 doneProcessing = true ;
6773 }
6874
6975 //
7076 } else {
71- res . status ( 500 ) . send ( error . toString ( ) ) ;
77+ res
78+ . status ( 200 )
79+ . send ( error ?. reason || error ?. toString ( ) || "500 Server Error" ) ;
7280 doneProcessing = true ;
7381 }
7482 }
0 commit comments