сделали так, что если юрл не пин - то файл, если пин - значение пина, иначе ошибка
This commit is contained in:
		
							parent
							
								
									a37c3ba7f9
								
							
						
					
					
						commit
						096f60baa0
					
				
							
								
								
									
										16
									
								
								index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								index.html
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,16 @@ | |||||||
|  | <!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="значение-ножки-сейчас--">Значение ножки сейчас -</h1> | ||||||
|  | </div> | ||||||
|  | </body> | ||||||
|  | 
 | ||||||
|  | </html> | ||||||
							
								
								
									
										28
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								index.js
									
									
									
									
									
								
							| @ -13,12 +13,12 @@ | |||||||
| //   port.on('data', function (data) {
 | //   port.on('data', function (data) {
 | ||||||
| //     console.log('Data:', data.toString('UTF8'))
 | //     console.log('Data:', data.toString('UTF8'))
 | ||||||
| //   })
 | //   })
 | ||||||
| 
 | const fs = require('fs'); | ||||||
| const http = require('node:http'); | const http = require('node:http'); | ||||||
| const { SerialPort } = require('serialport') | const { SerialPort } = require('serialport') | ||||||
| const { ReadlineParser } = require('@serialport/parser-readline') | const { ReadlineParser } = require('@serialport/parser-readline') | ||||||
| 
 | 
 | ||||||
| const port = new SerialPort({ path: '/com16', baudRate: 9600 }) | const port = new SerialPort({ path: '/com9', baudRate: 9600 }) | ||||||
| 
 | 
 | ||||||
| var str = ""; | var str = ""; | ||||||
| 
 | 
 | ||||||
| @ -33,8 +33,28 @@ parser.on('data', (data) => { | |||||||
| 
 | 
 | ||||||
| // Create a local server to receive data from
 | // Create a local server to receive data from
 | ||||||
| const server = http.createServer((req, res) => { | const server = http.createServer((req, res) => { | ||||||
|   res.writeHead(200, { 'Content-Type': 'application/json' }); |   console.log(req.url); | ||||||
|   res.end(str); | if(req.url=='/'){ | ||||||
|  |     fs.readFile('index.html', (err,data) => { | ||||||
|  |       if(err){ | ||||||
|  |         res.writeHead(404, "Not Found"); | ||||||
|  |         res.write("No file found") | ||||||
|  |         res.end(); | ||||||
|  |       } else { | ||||||
|  |         res.writeHead(200, { | ||||||
|  |           'Content-Type': 'text/html'  | ||||||
|  |         }) | ||||||
|  |         res.write(data) | ||||||
|  |         res.end(); | ||||||
|  |       } | ||||||
|  |     }) | ||||||
|  |   } else if(req.url=='/pin'){ | ||||||
|  |     res.writeHead(200, {'Content-Type': 'application/json'}); | ||||||
|  |     res.end(str); | ||||||
|  |   } else{ | ||||||
|  |     res.writeHead(404, "Not Found"); | ||||||
|  |     res.end(); | ||||||
|  |   } | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| server.listen(2048); | server.listen(2048); | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user