当我在浏览器的显示页面brank页面上打开应用程序时,我已经将平均堆栈api angular 6部署到了heroku,
在我的server.js中,这就是我所拥有的
const express = require('express');
const path = require('path');
const flash = require('connect-flash');
const bodyParser = require('body-parser');
const cors = require('cors');
const mongoose = require('mongoose');
const db = require('./app/config/database');
// Connect To Database
mongoose.connect(db.database);
// On Connection
mongoose.connection.on('connected', () => {
console.log('Connected to database '+db.database);
});
// On Error
mongoose.connection.on('error', (err) => {
console.log('Database error: '+err);
});
const app = express();
const movies = require('./app/routes/movies');
// Port Number
const port = process.env.PORT || 8000
// CORS Middleware
app.use(cors());
// Set Static Folder
app.use(express.static(path.join(__dirname, '/movies-client/dist')));
// Body Parser Middleware
app.use(bodyParser.json());
app.use('/movies', movies);
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname + '/movies-client/dist/movies-client/index.html'));
});
// Start Server
app.listen(port, () => {
console.log('Server started on port '+port);
});
当我运行heroku logs
时,这就是我的
2018-06-20T11:27:14.549707+00:00 heroku[router]: at=info method=GET path="/" host=damp-reef-60581.herokuapp.com request_id=f44c5f42-2bd0-42de-8a5d-18551c306fd0 fwd="212.91.22.46" dyno=web.1 connect=0ms service=50ms status=200 bytes=1191 protocol=https
2018-06-20T11:27:15.041658+00:00 heroku[router]: at=info method=GET path="/runtime.js" host=damp-reef-60581.herokuapp.com request_id=197ccaba-2fa8-42d6-8293-bc481fdf3fc3 fwd="212.91.22.46" dyno=web.1 connect=0ms service=16ms status=200 bytes=1191 protocol=https
2018-06-20T11:27:15.313302+00:00 heroku[router]: at=info method=GET path="/styles.js" host=damp-reef-60581.herokuapp.com request_id=46f87c24-9a16-4d45-82e0-295b184dceec fwd="212.91.22.46" dyno=web.1 connect=0ms service=3ms status=200 bytes=1191 protocol=https
2018-06-20T11:27:16.017486+00:00 heroku[router]: at=info method=GET path="/polyfills.js" host=damp-reef-60581.herokuapp.com request_id=7dd4bb06-ce65-472b-a8d3-106882666a11 fwd="212.91.22.46" dyno=web.1 connect=0ms service=9ms status=200 bytes=1191 protocol=https
2018-06-20T11:27:16.015745+00:00 heroku[router]: at=info method=GET path="/main.js" host=damp-reef-60581.herokuapp.com request_id=1ec5edd6-632d-4b37-9984-fd076fe9a083 fwd="212.91.22.46" dyno=web.1 connect=0ms service=6ms status=200 bytes=1191 protocol=https
2018-06-20T11:27:16.575143+00:00 heroku[router]: at=info method=GET path="/vendor.js" host=damp-reef-60581.herokuapp.com request_id=94178235-0013-49e6-aaa9-d34b84cc78ef fwd="212.91.22.46" dyno=web.1 connect=1ms service=3ms status=200 bytes=1191 protocol=https
当我检查浏览器时,显示此错误:
Uncaught SyntaxError: Unexpected token <
polyfills.js:1 Uncaught SyntaxError: Unexpected token <
styles.js:1 Uncaught SyntaxError: Unexpected token <
vendor.js:1 Uncaught SyntaxError: Unexpected token <
main.js:1 Uncaught SyntaxError: Unexpected token <
我有dist文件的客户端应用程序的
为什么会出现此错误?以及我该如何解决?任何帮助或建议都会有所帮助
答案 0 :(得分:1)
为了开始调试您的应用,请尝试用斜杠替换通配符,因为通配符可以覆盖/movies
路由
也许是你的路途
app.use(express.static(path.join(__dirname, '/movies-client/dist')));
似乎是错误的
app.use(express.static(path.join(__dirname, '/movies-client/dist/movies-client')));
答案 1 :(得分:0)
我进行了以下更改以部署到Heroku。