I am trying to learn to use the Connect.js static middleware, but all the examples I find use the static command as either a function, or a getter, some use a method called use(), while others don't. Frankly, I'm stumped.

I am doing this in CoffeeScript. Here is my code:

connect = require 'connect'
fs = require 'fs'

server = connect.createServer (req,res)->
 console.log 'Incoming Request:' + req.url
 connect.static(__dirname="/static");
 fs.readFile 'index.html',  (err,data)->

  if not err
    res.write data
    res.end()
server.listen 7243

The index.html has a .jpg file that is in the /static directory. The index.html file is served, but the image always appears as a broken link. Can someone tell me what I am doing wrong? Any info will be appreciated. Thanks!

有帮助吗?

解决方案

Maybe you should change

connect.static(__dirname="/static");

to the correct

connect.static(__dirname+"/static");

or the longer

connect.static("#{__dirname}/static");
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top