-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tried to send msg through child process not working rn
- Loading branch information
1 parent
acc45c5
commit 2d2bafc
Showing
3 changed files
with
41 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import axios from 'axios'; | ||
|
||
process.stdin.setEncoding('utf8'); | ||
|
||
process.stdin.on('data', async (data) => { | ||
const requestData = JSON.parse(data); | ||
|
||
try { | ||
const response = await axios(requestData); | ||
console.log(response.data); | ||
} catch (error) { | ||
console.error('Error sending data:', error); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,27 @@ | ||
import axios from 'axios' | ||
import { messageDataType } from '../types' | ||
import { spawn } from 'child_process'; | ||
import axios from 'axios'; | ||
import { messageDataType } from '../types'; | ||
|
||
|
||
export const sendDataSAbackend = async (messageData : messageDataType) => { | ||
const apiUrl = `` | ||
export const sendDataSAbackend = async (messageData: messageDataType) => { | ||
const apiUrl = 'YOUR_BACKEND_ENDPOINT_URL'; | ||
|
||
const body = { | ||
method : 'post', | ||
url : apiUrl, | ||
data : messageData, | ||
headers : '' | ||
} | ||
} | ||
method: 'post', | ||
url: apiUrl, | ||
data: messageData, | ||
headers: { 'Content-Type': 'application/json' } // Assuming JSON data | ||
}; | ||
|
||
const child = spawn('node', ['child_process.js'], { stdio: 'inherit' }); // Spawning child process | ||
|
||
child.on('exit', (code) => { | ||
console.log(`Child process exited with code ${code}`); | ||
}); | ||
|
||
child.on('error', (err) => { | ||
console.error('Failed to start subprocess.', err); | ||
}); | ||
|
||
child?.stdin?.write(JSON.stringify(body)); // Sending data to child process | ||
child?.stdin?.end(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters