2017-06-27 38 views
0

這是一個服務器的配置代碼:如何在沒有index.html的情況下在'/'上進行快遞服務?

const app = new WebpackDevServer(compiler, { 
    contentBase: '/public/', 
    proxy: {'/graphql': `http://localhost:${GRAPHQL_PORT}`}, 
    publicPath: '/js/', 
    stats: {colors: true}, 
}); 
// Serve static resources 
app.use('/', express.static(path.resolve(__dirname, 'public'))); 

,當應用程序運行時,它是在localhost:3000/index.html的,我想渲染localhost上的應用程序:3000 /。我怎樣才能做到這一點?我有這個問題,因爲如果沒有錯誤,反應路由器不要在我的代碼工作:

<BrowserRouter> 
     <Route exact path='/' component={App}/> 
    </BrowserRouter> 

,並在localhost:3000 /這是我的輸出:

result

回答

0

假設你的索引html的是公共文件夾中,當你已經宣佈它爲static,你可以爲你的應用程序一樣

app.get('/', function(res){ 
    res.sendfile('public/index.html'); 
}) 

然後你就可以訪問你的應用程序作出反應與

http://localhost:3000/ 
相關問題