我正在启动一个MEA2N应用程序,并构建了在端口3000上运行的小型Express服务器。Angular App在端口4200上运行。如果我打开Localhost 3000,我会看到"加载...",该应用程序不运行。如果我打开Local -Host 4000,我会得到"应用程序工作"。有人知道这可能发生吗?
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在根文件夹中运行。Angular App是root/src/indxex.html和root/src/app/
如果server.js
在root
文件夹中,并且Angular App在root/src/index.html
然后
app.use(express.static(path.join(__dirname, 'dist')));
应该是
app.use(express.static(path.join(__dirname, '/src')));