我无法弄清楚为什么这不起作用。我传递这个反向代理,例如mkteagle / admin会将我发送给mkteagle:8083。但它就像快递无法在mkteagle:8083 / dist / script.js找到我的静态文件。它加载index.html很好,而不是同一文件夹中的静态文件。
// Get dependencies
const express = require('express');
const path = require('path');
const http = require('http');
const bodyParser = require('body-parser');
const cors = require('cors');
// Get our API routes
const api = require('./server/routes/api');
const app = express();
app.use(cors());
// Parsers for POST data
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
// Point static path to dist
// serve angular front end files from root path
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, 'index.html'));
});
/**
* Get port from environment and store in Express.
*/
const port = process.env.PORT || '8082';
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}`));