我正在尝试从节点调用Angular,但在浏览器中遇到以下错误。使用“节点服务器”时成功调用Angular。
错误:
runtime.js:1 Uncaught SyntaxError: Unexpected token <
polyfills.js:1 Uncaught SyntaxError: Unexpected token <
styles.js:1 Uncaught SyntaxError: Unexpected token <
scripts.js:1 Uncaught SyntaxError: Unexpected token <
vendor.js:1 Uncaught SyntaxError: Unexpected token <
main.js:1 Uncaught SyntaxError: Unexpected token <
server.js
const path = require('path');
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
process.env.INDEX = path.join(__dirname, '/dist/nghd01/index.html');
const configureMongoose = require('./backend/config/mongoose')
const configureExpress = require('./backend/config/express')
const app = configureExpress();
app.listen(4200);
express.js
module.exports = function() {
const app = express();
require('../app/routes/index.server.routes')(app);
return app;
}
index.server.routes.js
const index = require('../controllers/index.server.controller');
module.exports = (app) => {
app.get('/*', index.render);
};
index.server.controller.js
exports.render = (req, res) => {
res.sendFile(process.env.INDEX)
}
答案 0 :(得分:0)
我在express.js中缺少一行。我没有像这样指定静态文件的位置:
TableEndPoint