-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
31 lines (25 loc) · 897 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const content = require('fs').readFileSync(__dirname + '/indexsocket.html', 'utf8');
const httpServer = require('http').createServer((req, res) => {
// serve the index.html file
res.setHeader('Content-Type', 'text/html');
res.setHeader('Content-Length', Buffer.byteLength(content));
res.end(content);
});
const io = require('socket.io')(httpServer);
const fetch = require("node-fetch");
io.on('connect', socket => {
console.log('connect');
});
httpServer.listen(3000, () => {
console.log('go to http://localhost:3000');
});
io.on('connect', socket => {
socket.on('hey', data => {
console.log('hey', data);
//HEJ :) Här är node-fetch. Denna funkade i gustavsnode.js, men inte i index.ts.
// fetch("http://" + 192.168.1.13 + ":" + 3558, {
// method: "PUT",
// body: ";slider1 " + 3 + ";"
// });
});
});