I have an api route /auth/calculator and the handler spawns a child_process and then invokes a python script. The problem is my webpack bundler with nextjs doesn't copy the python file over to /build/server/pages/api/calculator and so when node attempts to access the python file it fails. How do I edit the webpack config rules so that it will see the .py extension and just copy the file over to /build/server/pages/api/calculator/calculator.py. Thanks!
const spawn = require("child_process").spawn;
const process = spawn("python3", [
`${path.join(__dirname)}/calculator.py`
JSON.stringify(clientData),
]);
process.stdout.on("data", function (data) {
return res.send(data.toString());
});
process.stderr.on("data", (data) => {
console.error(`stderr: ${data}`);
});
process.on("close", (code) => {
console.log(`child process exited with code ${code}`);
});