语法错误:预期的表达式,得到“<"

编程入门 行业动态 更新时间:2024-10-28 06:36:13
本文介绍了语法错误:预期的表达式,得到“<"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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.jsangular.min.js 之类的 JavaScript 文件时,您的服务器将返回 index.html,以 开头,这会导致 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.

这篇关于语法错误:预期的表达式,得到“&lt;"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-22 08:29:37,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表达式   语法错误   amp   lt   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!