I want to create a chat with vue.js, socket.js and node.js, I created an API before and I want to add socket.js but when I start the app the app correctly connects to my API and to socket .js but I see in the response request: "We're sorry but the application is not working properly without JavaScript enabled. Please enable it to continue." I searched but I can't find :(
the code of main.js (vue.js) script :
import Vue from 'vue'
import App from './App.vue
import { io } from "socket.io-client";
io();
Vue.config.productionTip = false
new Vue({
render: h => h(App),
}).$mount('#app')
the code of index.js (API) :
const express = require('express')
const userRoute = require('./routes/userRoutes')
const messageRoute = require('./routes/messageRoutes')
const mongoose = require('mongoose')
const { createServer } = require("http");
const { Server } = require("socket.io");
require('dotenv').config()
const app = express()
const httpServer = createServer(app);
const io = new Server(httpServer, {
cors: {
origin: "*",
credentials: true
}
});
app.use(express.json())
mongoose.connect('mongodb+srv://'+ process.env.DB_NAME + ':' + process.env.DB_PASSWORD + '@' + process.env.DB_IP + '/' + process.env.DB_NAME +'?retryWrites=true&w=majority', {useNewUrlParser: true});
app.use((req, res, next) => {
res.append('Access-Control-Allow-Origin', ['http://localhost:8080']);
res.append('Access-Control-Allow-Methods', 'GET,PATCH,POST,DELETE');
res.append('Access-Control-Allow-Headers', ['*']);
next();
});
app.use('/users', userRoute)
app.use('/messages', messageRoute)
io.on("connection", (socket) => {
console.log(socket.id)
io.emit('news','Voici un nouvel élément envoyé par le serveur')
});
httpServer.listen(process.env.APP_PORT, () => {
console.log("Serveur à l'écoute")
})
thank you for your answers