English 中文(简体)
意想不到的“indent”
原标题:Express throwing unexpected token "indent"

I m trying to deliver a static html file which uses jquery and other libraries and i want to know how to do his with express.

这里的我手法(明示服务器档案)

var express = require( express ) 
 , routes = require( ./routes ) 
var app = module.exports = express.createServer(); 
app.configure(function(){ 
 app.set( views , __dirname +  /views ); 
 app.use(express.static(__dirname +  /public )); 
}); 

app.configure( development , function(){ 
 app.use(express.errorHandler({ dumpExceptions: true, showStack: 
true })); 
}); 

app.configure( production , function(){ 
 app.use(express.errorHandler()); 
}); 

app.register( .html , require( jade )); 
app.get( / , function(req, res) { 
   res.render( index.html ); 
}); 

app.listen(3000); 

页: 1

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http:// 
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html> 
<head> 
<link rel= stylesheet  type= text/css  href= theme.css  /> 
<link rel= stylesheet  type= text/css  href= fullcalendar.css  /> 
<link rel= stylesheet  type= text/css  href= fullcalendar.print.css  
media= print  /> 
<script type= text/javascript  src= jquery-ui-1.8.11.custom.min.js ></ 
script> 
<script type= text/javascript  src= jquery-1.5.2.min.js ></script> 
<script type= text/javascript  src= fullcalendar.min.js ></script> 
<script type= text/javascript > 
       $(document).ready(function() { 
               $( #calendar ).fullCalendar({ 
                       theme: true, 
                       header: { 
                               left:  prev,next today , 
                               center:  title , 
                               right:  month  
                       }, 
                       editable: true, 
                       events: { url :  http://localhost:5555/ }, 
                       firstDay : 1, 
                       weekends : true 
               }); 
       }); 
</script> 
<style type= text/css > 
       body { 
               margin-top: 40px; 
               text-align: center; 
               font-size: 13px; 
               font-family: "Lucida 
Grande",Helvetica,Arial,Verdana,sans-serif; 
               } 
       #calendar { 
               width: 900px; 
               margin: 0 auto; 
               } 
</style> 
</head> 
<body> 
<div id= calendar ></div> 
</body> 
</html> 

以及当我操作服务器和把我的浏览器放在服务器上时,就会出现环礁错误。

Error: D:Workspace
odejs	estmy-server/views/index.html:12 
   10| <script type= text/javascript > 
   11| 
 > 12|         $(document).ready(function() { 
   13| 
   14|                 $( #calendar ).fullCalendar({ 
   15|                         theme: true, 
unexpected token "indent" 
   at Object.parseExpr (D:Workspace
odejs	estmy-server 

ode_modulesjadelibparser.js:228:15) 
   at Object.parse (D:Workspace
odejs	estmy-server
ode_modules 
jadelibparser.js:129:25) 
   at parse (D:Workspace
odejs	estmy-server
ode_modulesjadelib 
jade.js:101:62) 
   at Object.compile (D:Workspace
odejs	estmy-server
ode_modules 
jadelibjade.js:148:9) 

I did initial googling, but coudn t figure much.. can somone let know wht s happening. Thanks

问题回答

问题在于<代码>.html与jade模板发动机的联系。 Jade要求html档案类似:

!!! 5
html(lang="en")
  head
    title= pageTitle
    script(type= text/javascript )
      if (foo) {
         bar()
      }
  body
    h1 Jade - node template engine
    #container
      - if (youAreUsingJade)
        p You are amazing
      - else
        p Get on it!

在你的情况下,jade发动机试图将你的超文本文档作为jade模板和磨擦。 如果你真的想要提供纯超文件,你可以查询。 页: 1

just for anyone who is going though this . You are most probably following the example over here .

https://github.com/visionmedia/express/blob/master/examples/ejs/index.js

如果你不希望也仍然有兴趣提供html的档案,请查阅。 那么,你们需要做的是使用。

如果贵项目不使用jade模板,那么就只用ed子( Package.json。 档案:

"jade": "*"

页: 1

"ejs": "*"

接着,你对以下假设表示非常好:

app.engine( .html , require( ejs ).__express);

app.set( view engine ,  html );

确实,秩序很重要。

render(>>>>>将“index.html”作为模版处理,并试图通过排位机(jade)处理。 由于您的超文本文件为 而不是>/em>格式模版(仅是静态的超文本文档),你重犯了错误。

如果你想简单地为静态档案索引.html服务,那么就把它列入在<代码>app.use(express.static(__dirname + /public ));上的静态目录,并直接查阅。 静态目录中的文件没有预先处理。 如果你重新努力做一些比较复杂的事,你可能还需要混淆快的中华。 http://expressjs.com/guide.html

也可以使用<代码>f模块读到文档内容,并使用(如你目前试图做的事),但采用不必要的间接费用:

//var fs = require( fs );
app.get( /html , function(req, res) { 
  res.writeHead(200, { Content-Type :  text/html });
  var contents = fs.readFileSync("./public/index.html", "UTF-8");
  res.end(contents);
}); 




相关问题
How to make Sequelize use singular table names

I have an model called User but Sequelize looks for the table USERS whenever I am trying to save in the DB. Does anyone know how to set Sequelize to use singular table names? Thanks.

What is Node.js? [closed]

I don t fully get what Node.js is all about. Maybe it s because I am mainly a web based business application developer. What is it and what is the use of it? My understanding so far is that: The ...

Clientside going serverside with node.js

I`ve been looking for a serverside language for some time, and python got my attention somewhat. But as I already know and love javascript, I now want learn to code on the server with js and node.js. ...

Can I use jQuery with Node.js?

Is it possible to use jQuery selectors/DOM manipulation on the server-side using Node.js?

How do I escape a string for a shell command in node?

In nodejs, the only way to execute external commands is via sys.exec(cmd). I d like to call an external command and give it data via stdin. In nodejs there does yet not appear to be a way to open a ...

热门标签