E
E
Evergarden772021-02-22 18:27:12
Node.js
Evergarden77, 2021-02-22 18:27:12

Why is there an error when connecting socket.io?

Index.html content

<!doctype html>
<html lang="ru">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/3.1.1/socket.io.min.js"></script>
<script>
    const socket = io("http://localhost:3000");
</script>
</body>
</html>


The content of index.ts
import mongoose  from 'mongoose';
import express  from 'express';
import bodyParser from "body-parser";
import {UserController, dialogController} from "./controlers";
import MessageController from "./controlers/MessageController";
import {updateLastSeen,checkAuth} from "./middleware";
import dotenv from 'dotenv';



const app = express()
const http = require('http').Server(app);
const io = require('socket.io')(http);
// @ts-ignore

const port = 3000

const User = new UserController();
const Dialog = new dialogController();
const Messages = new MessageController();





app.use(bodyParser.json());
app.use(updateLastSeen);
app.use(checkAuth)
dotenv.config();

mongoose.connect('mongodb://localhost:27017/chat', {useNewUrlParser: true, useUnifiedTopology: true,useCreateIndex: true});

app.get('/user/me',User.getMe)
app.get('/user/:id',User.show)
app.post('/user/registration', User.create)
app.delete('/user/:id', User.delete)
app.post('/user/login', User.login)


app.get('/dialogs/',Dialog.index);
app.post('/dialogs',Dialog.create);
app.delete('/dialogs/:id',Dialog.delete);

app.get('/messages',Messages.index);
app.post('/messages',Messages.create);
app.delete('/messages/:id',Messages.delete);


// @ts-ignore
io.on('connection', function (socket){
    console.log("user connect")
})


http.listen(process.env.PORT, () => {
    console.log(`Example app listening at http://localhost:${port}`)
})


The mistake itself
6033cd4c3ec23927233309.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alams Stoyne, 2017-10-28
@kiril9011

if(!isset($_POST['submit'])){
Sign "!" remove it and you will be happy.
For now, the check looks something like this ^ if there is no variable passed using the post, then do it"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question