-
Notifications
You must be signed in to change notification settings - Fork 15.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
point people here if they have problems with serving static files
- Loading branch information
Showing
4 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
var express = require('../..'); | ||
var app = express(); | ||
|
||
// log requests | ||
app.use(express.logger('dev')); | ||
|
||
// express on its own has no notion | ||
// of a "file". The express.static() | ||
// middleware checks for a file matching | ||
// the `req.path` within the directory | ||
// that you pass it. In this case "GET /js/app.js" | ||
// will look for "./public/js/app.js". | ||
|
||
app.use(express.static(__dirname + '/public')); | ||
|
||
// if you wanted to "prefix" you may use | ||
// the mounting feature of Connect, for example | ||
// "GET /static/js/app.js" instead of "GET /js/app.js". | ||
// The mount-path "/static" is simply removed before | ||
// passing control to the express.static() middleware, | ||
// thus it serves the file correctly by ignoring "/static" | ||
app.use('/static', express.static(__dirname + '/public')); | ||
|
||
// if for some reason you want to serve files from | ||
// several directories, you can use express.static() | ||
// multiple times! Here we're passing "./public/css", | ||
// this will allow "GET /style.css" instead of "GET /css/style.css": | ||
app.use(express.static(__dirname + '/public/css')); | ||
|
||
app.listen(3000); | ||
console.log('listening on port 3000'); | ||
console.log('try:'); | ||
console.log(' GET /hello.txt'); | ||
console.log(' GET /js/app.js'); | ||
console.log(' GET /css/style.css'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
body { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hey |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
foo |