add_server_react
This commit is contained in:
parent
adbf8b644d
commit
01b5f88e31
20
index.html
Normal file
20
index.html
Normal file
@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Welcome file</title>
|
||||
<link rel="stylesheet" href="https://stackedit.io/style.css" />
|
||||
</head>
|
||||
|
||||
<body class="stackedit">
|
||||
<div class="stackedit__html"><h1 id="состояние-ардуины-отображается-в-браузере"><em>Состояние ардуины отображается в браузере:</em></h1>
|
||||
<h2 id="ответ-на-hello">ответ на “hello”</h2>
|
||||
<p>Пришел ответ:</p>
|
||||
<h2 id="состояние-ардуины-равно">Состояние ардуины равно</h2>
|
||||
<p>Пришел ответ:</p>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
20
index.js
20
index.js
@ -11,8 +11,10 @@
|
||||
const { SerialPort } = require('serialport')
|
||||
const { ReadlineParser } = require('@serialport/parser-readline')
|
||||
const http = require('node:http');
|
||||
const fs = require('fs');
|
||||
const port = new SerialPort({ path: 'COM9', baudRate: 9600 })
|
||||
|
||||
|
||||
const parser = port.pipe(new ReadlineParser({ delimiter: '\r\n' }))
|
||||
|
||||
var value_arduino = "";
|
||||
@ -25,16 +27,30 @@ parser.on('data', (data => {
|
||||
}));
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
|
||||
|
||||
console.log( req.url);
|
||||
if (req.url == "/hello") {
|
||||
res.end("/hello");
|
||||
|
||||
}else
|
||||
{
|
||||
if (req.url == "/") {
|
||||
|
||||
fs.readFile('D:/medvedevis/index.html', 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return;
|
||||
}
|
||||
res.writeHead(200,{ 'Content-Type': 'text/html' });
|
||||
res.end(data);
|
||||
});
|
||||
}
|
||||
else {
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
res.end(value_arduino);
|
||||
console.log( req.url);
|
||||
}
|
||||
}}
|
||||
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user