0

I'm not sure what I'm doing wrong here... Here's my file structure...

/app
  /scripts/components/post
    /post.html
    /PostCtrl.js

Here's my express use

var publicDir = path.join(__dirname, 'app'));
app.use(express.static(publicDir));
app.use(app.router);

I have confirmed that publicDir is the directory I want to be serving up.

I'm not certain what is wrong with my setup. Am I using this incorrectly?

kentcdodds
  • 27,113
  • 32
  • 108
  • 187
  • 1
    Can you add what specific path you're trying to hit? Like, what are you putting in your browser's address bar? Also, what platform are you running on? Is your OS case-sensitive with filenames? – juanpaco Jan 14 '14 at 18:40

2 Answers2

0

the app.router should come before the express.static line in your middleware chain.

var publicDir = path.join(__dirname, 'app'));
app.use(app.router);
app.use(express.static(publicDir));

You could also consider using ecstatic module instead for serving static files. It is more flexible than the standard express static middleware.

var ecstatic = require('ecstatic')
app.use(app.router)
app.use(staticMiddleware())

function staticMiddleware() {
  var rootPath = path.join(__dirname, 'public')
  var ecstaticOpts = {
    root: rootPath,
    baseDir: '/',
    showDir: true
  }
  return ecstatic(ecstaticOpts)
}
Noah
  • 33,851
  • 5
  • 37
  • 32
  • I don't believe that is true. I believe you want the `app.router` to be the last thing you use... – kentcdodds Jan 14 '14 at 21:46
  • See this answer. http://stackoverflow.com/a/12695813/1095114. Specifically "Usually, you want to put the router above the static middleware so that a accidentally-named file can't override one of your routes." There are arguments for each scenario so I guess it depends on your specific circumstances. – Noah Jan 14 '14 at 21:56
-1

I discovered there was something unrelated in my other code that was causing the issue. I had nothing wrong with my static file setup.

kentcdodds
  • 27,113
  • 32
  • 108
  • 187