|
|
|
@ -6,26 +6,14 @@ const { execSync } = require('child_process');
|
|
|
|
const app = express()
|
|
|
|
const app = express()
|
|
|
|
app.use(express.json())
|
|
|
|
app.use(express.json())
|
|
|
|
|
|
|
|
|
|
|
|
app.use((req, res, next) => {
|
|
|
|
const cors = require('cors');
|
|
|
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
|
|
app.use(cors());
|
|
|
|
res.setHeader("Access-Control-Allow-Methods", "POST, OPTIONS");
|
|
|
|
|
|
|
|
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
|
|
|
|
|
|
|
|
res.setHeader("Access-Control-Allow-Private-Network", "true");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (req.method === "OPTIONS") {
|
|
|
|
|
|
|
|
return res.status(204).end();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
next();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//const cors = require('cors');
|
|
|
|
|
|
|
|
//app.use(cors());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.post('/prompt', (req, res)=>{
|
|
|
|
app.post('/prompt', (req, res)=>{
|
|
|
|
|
|
|
|
|
|
|
|
const resumeFlag = process.env.SESSIONID ? `--resume "${process.env.SESSIONID}"` : '';
|
|
|
|
const resumeFlag = process.env.SESSIONID ? `--resume "${process.env.SESSIONID}"` : '';
|
|
|
|
const result = execSync(
|
|
|
|
const result = execSync(
|
|
|
|
`cd /home/matt/pathfinder && claude -p "${req.body.message}" ${resumeFlag} --output-format json --allowedTools "Bash(*)" "Read(*)" "Write(*)" "Edit(*)"`,
|
|
|
|
`cd /home/matt/pathfinder && claude -p "${req.body.content}" ${resumeFlag} --output-format json --allowedTools "Bash(*)" "Read(*)" "Write(*)" "Edit(*)"`,
|
|
|
|
{ encoding: 'utf-8', timeout: 120000 }
|
|
|
|
{ encoding: 'utf-8', timeout: 120000 }
|
|
|
|
);
|
|
|
|
);
|
|
|
|
fs.writeFileSync('.env', `SESSIONID="${JSON.parse(result).session_id}"`, 'utf8');
|
|
|
|
fs.writeFileSync('.env', `SESSIONID="${JSON.parse(result).session_id}"`, 'utf8');
|
|
|
|
|