获取http:// localhost:3000/404(未找到)

时间:2017-06-13 14:30:01

标签: node.js reactjs webpack

我试图用节点服务器启动react-js app。 目录结构: MyTodo

---仓/

------ CSS /

------字体/

------ JS /

------的index.html

---源/

------ App.jsx

------ TodoGroup /

file server.js:



 var express=require('express');
var app=express();

app.set('port',(process.env.PORT||3000));

app.use('/',express.static(__dirname));

app.listen(app.get('port'), function() {
	console.log('Server started: http://localhost:'+app.get('port')+'/');
});




webpack.config:



var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require("extract-text-webpack-plugin");

var config = module.exports = {
    context: __dirname,
    entry: {
        'App': './sources/App.jsx',
    },

    output: {
        path: './bin/js',
        filename: '[name].js'
    },

    plugins: [
        new ExtractTextPlugin('../css/[name].css')
    ],

	devServer: {
        contentBase: ".",
        host: "localhost",
        port: 3000
    },
	
   module:{
        loaders:[   //загрузчики
            {
                test: /\.jsx?$/, // определяем тип файлов
                exclude: /(node_modules)/,
                loader: "babel-loader",
                query:{
                    presets:["es2015", "react"]
                }
            }
        ]
    }

    resolve: {
        extensions: ['', '.js', '.jsx']
    }
}




在浏览器http://localhost:3000/中显示错误: 获取http://localhost:3000/ 404(未找到)

1 个答案:

答案 0 :(得分:1)

您没有任何处理http://localhost:3000/

的路线

你只有静态文件处理程序,这意味着这个网址可能会起作用 http://localhost:3000/index.html

如果您想在http://localhost:3000/访问您的网络,请添加此

app.get('/', function(req, res){
    res.sendFile(__dirname+'/bin/index.html'); // change the path to your index.html
});