2017-02-18 70 views
0

我開始MEA2N應用程序,並構建了一個運行在端口3000上的小型快遞服務器。 角度應用程序運行在端口4200.如果我打開本地主機3000,正在加載...'如果應用程序無法運行。而如果我打開本地主機4000我得到'應用程序工作'。有人知道這可能會發生嗎?角度2文件直接工作,但不通過nodejs快遞文件

server.js是很標準:

// Get dependencies 
const express = require('express'); 
const path = require('path'); 
const http = require('http'); 
const bodyParser = require('body-parser'); 

// Get our API routes 
const api = require('./server/routes/api'); 

const app = express(); 

// Parsers for POST data 
app.use(bodyParser.json()); 
app.use(bodyParser.urlencoded({ extended: false })); 

// Point static path to dist 
app.use(express.static(path.join(__dirname, 'dist'))); 

// Set our api routes 
app.use('/api', api); 

// Catch all other routes and return the index file 
app.get('*', (req, res) => { 
    res.sendFile(path.join(__dirname, './src/index.html')); 
}); 

/** 
* Get port from environment and store in Express. 
*/ 
const port = process.env.PORT || '3000'; 
app.set('port', port); 

/** 
* Create HTTP server. 
*/ 
const server = http.createServer(app); 

/** 
* Listen on provided port, on all network interfaces. 
*/ 
server.listen(port,() => console.log(`API running on localhost:${port}`)); 

server.js在根文件夾中運行。 角的應用程序是根/ SRC/indxex.html和根/ SRC /應用/

+0

請包括您的文件夾結構和您的app.js – echonax

回答

0

server.js如果在root文件夾和角度的應用程序是對root/src/index.html

然後

app.use(express.static(path.join(__dirname, 'dist'))); 

應該是

app.use(express.static(path.join(__dirname, '/src'))); 
+1

你是完全正確的。我已經改變了這部分,不幸的是仍然沒有效果。打開localhost 4200的作品。打開本地主機3000不 – Mihaly

+0

@Mihaly任何錯誤?檢查鉻開發人員工具的網絡選項卡,看看它是否可以找到index.html – echonax

+0

沒有沒有不幸的。 – Mihaly