如何解决WDS 断开连接! sockjs-node 被拒绝,webpack-dev-middleware,expressjs
这里有一些 sockjs 节点错误
我正在使用 express 构建开发服务器...
为我的 webpack-dev-middleware
webpack-hot-middleware
和 React
这是我的webpack.config.js
:
// require('dotenv').config()
const ESLintPlugin = require('eslint-webpack-plugin')
const ErrorOverlayPlugin = require('error-overlay-webpack-plugin')
const HTMLWebpackPlugin = require('html-webpack-plugin')
const { WebpackManifestPlugin } = require('webpack-manifest-plugin')
const path = require('path')
const webpack = require('webpack');
const eslintPlugin = new ESLintPlugin({ fix: true })
const manifestPlugin = new WebpackManifestPlugin()
const HMRPlugin = new webpack.HotModuleReplacementPlugin()
const htmlPlugin = new HTMLWebpackPlugin({
template: path.resolve(__dirname,'build/app.html'),filename: 'index.html',})
const errorPlugin = new ErrorOverlayPlugin()
module.exports = {
mode: 'development',entry: [
'webpack-dev-server/client?http://127.0.0.1:3999/','webpack/hot/only-dev-server','./src/index.js',],output: {
path: path.resolve(__dirname,'build'),filename: 'main.bundle.js',publicPath: '/',pathinfo: true,},devServer: {
socket: 'socket',hot: true,overlay: true,port: 3999,inline: true,stats: 'normal',historyApiFallback: true,performance: {
hints: false,module: {
rules: [
{
test: /\.(js|jsx)$/,include: path.resolve(__dirname,'src'),exclude: /node_modules/,use: ['babel-loader'],{
test: /\.(scss)$/,use: ['style-loader','css-loader','sass-loader'],{
test: /\.(png|svg|jpe?g|gif|ico)$/i,type: 'asset/resource',{
test: /\.(woff|woff2|eot|ttf|otf)$/i,plugins: [eslintPlugin,manifestPlugin,errorPlugin,htmlPlugin,HMRPlugin],devtool: 'cheap-module-source-map',}
我的server.js
:
import express from 'express'
import debug from 'debug'
import logger from 'morgan'
import chalk from 'chalk'
import dotenv from 'dotenv'
import webpack from 'webpack'
import hotMiddleware from 'webpack-hot-middleware'
import wpDevMiddleware from 'webpack-dev-middleware'
import cors from 'cors'
import wpConf from './webpack.config'
dotenv.config()
const app = express()
const port = process.env.PORT
const ecoS = debug('ECO-Server')
const ecoC = debug('ECO-Client')
const compiler = webpack(wpConf)
const skipLog = (req,res) => {
var { url } = req
if (url.match(/sockjs/gi)) {
return true
}
return false
}
app.set('port',port)
app.use(cors({ maxAge: 1000 * 60 * 60 * 24 * 2 }))
app.use(
logger('dev',{
stream: {
write: msg => ecoC(msg.trimEnd()),skip: skipLog,})
)
app.use(wpDevMiddleware(compiler))
app.use(hotMiddleware(compiler))
setTimeout(() => {
app.listen(port,() => ecoS('Listening on port',chalk.cyanBright(port)))
},4000)
127.0.0.1:3999/sockjs-node/info?t=1615910198493:1 Failed to load resource: net::ERR_CONNECTION_REFUSED
sockjs.js:1609 XHR Failed loading: GET "http://127.0.0.1:3999/sockjs-node/info?t=1615910266231".
请帮我这个……有人吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。