I've added another panel aside the main one, called 'server' which intended to expose my main panel to outside apps.
My folder structure is as follows:
├── js
...
│ ├── lib
...
│ ├── main
...
│ ├── server
│ │ ├── index.html
│ │ └── index.ts
...
src/serve/index.ts code:
import { http } from "../lib/cep/node";
const port = 8088;
const server = http.createServer((req, res) => {
console.log(req);
if (req.url === '/ping') {
res.setHeader('Content-Type', 'text/plain');
res.end('pong');
} else {
res.setHeader('Content-Type', 'text/plain');
res.statusCode = 400;
res.end('METHOD_NOT_ALLOWED');
}
});
server.listen(port, () => {
console.log(`Server is running at http://localhost:${port}`);
console.log(server.listening);
});
The problem:
Each time I save any file HMR is triggered for all the files under src(and I do get that it's expected behavior) causing the listen function to re-run and raise the EADDRINUSE error.
My workaround:
Adding the following line to the triggerHMR function that's inside vite.es.config.ts:
if (panel.name === "server") return;
triggerHMR looks like that right now:
const triggerHMR = () => {
// No built-in way to trigger Vite's HMR reload from outside the root folder
// Workaround will read and save index.html file for each panel to triggger reload
console.log("ExtendScript Change");
cepConfig.panels.map((panel) => {
if (panel.name === "server") return; // this is my addition
const tmpPath = path.join(process.cwd(), "src", "js", panel.mainPath);
if (fs.existsSync(tmpPath)) {
const txt = fs.readFileSync(tmpPath, { encoding: "utf-8" });
fs.writeFileSync(tmpPath, txt, { encoding: "utf-8" });
}
});
};
So ultimately I'm losing the HMR feature for that panel, and each time I want it's code changes to take place I have to rebuild and restart After Effects..
Any ideas how to properly overcome that?
I've added another panel aside the main one, called 'server' which intended to expose my main panel to outside apps.
My folder structure is as follows:
src/serve/index.tscode:The problem:
Each time I save any file HMR is triggered for all the files under
src(and I do get that it's expected behavior) causing thelistenfunction to re-run and raise theEADDRINUSEerror.My workaround:
Adding the following line to the
triggerHMRfunction that's insidevite.es.config.ts:triggerHMRlooks like that right now:So ultimately I'm losing the HMR feature for that panel, and each time I want it's code changes to take place I have to rebuild and restart After Effects..
Any ideas how to properly overcome that?