2017-06-13 116 views
1

我试图启动react-js应用程序与节点服务器。目录 结构: MyTodoGET http:// localhost:3000/404(未找到)

---斌/

------ CSS/

------字体/

------ JS/

------的index.html

---源/

------ App.jsx

------ TodoGroup/

文件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() { 
 
\t 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') 
 
    ], 
 

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

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

在浏览器http://localhost:3000/显示了一个错误: GET http://localhost:3000/ 404(未找到)

+0

你的'server.js'在哪里?假设它在'bin /'的父节点中,则更新'app.use('/',express.static(path.join(__ dirname,“bin /”)));'Import'path'。 –

+0

谢谢你,Molda的回答工作 – Olga

回答

0

你不必处理http://localhost:3000/

任何途径你只有静态文件处理程序,这意味着该URL可能会工作 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 
}); 
+0

谢谢你,它的工作原理,但whith:res.sendFile(__ dirname +'/ bin/index.html'); – Olga

相关问题