问题描述
限时送ChatGPT账号..我收到 SyntaxError: expected expression, got '<'
当我执行以下节点代码时,控制台出现错误
I got SyntaxError: expected expression, got '<'
error in the console when i'm executing following node code
var express = require('express');
var app = express();
app.all('*', function (req, res) {
res.sendFile(__dirname+'/index.html') /* <= Where my ng-view is located */
})
var server = app.listen(3000, function () {
var host = server.address().address
var port = server.address().port
})
错误:
我正在使用 Angular Js,它的文件夹结构如下
I'm using Angular Js and it's folder structure like bellow
我错过了什么?
推荐答案
这段代码:
app.all('*', function (req, res) {
res.sendFile(__dirname+'/index.html') /* <= Where my ng-view is located */
})
告诉 Express,无论浏览器请求什么,您的服务器都应该返回 index.html
.因此,当浏览器请求 jquery-xyzmain.js
或 angular.min.js
之类的 JavaScript 文件时,您的服务器将返回 index.html的内容code>,以
开头,这会导致 JavaScript 错误.
tells Express that no matter what the browser requests, your server should return index.html
. So when the browser requests JavaScript files like jquery-x.y.z.main.js
or angular.min.js
, your server is returning the contents of index.html
, which start with <!DOCTYPE html>
, which causes the JavaScript error.
您在回调中的代码应该查看请求以确定要发回哪个文件,和/或您应该对 app.all
使用不同的路径模式.有关详细信息,请参阅路由指南.
Your code inside the callback should be looking at the request to determine which file to send back, and/or you should be using a different path pattern with app.all
. See the routing guide for details.
这篇关于语法错误:预期的表达式,得到“<"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论