Skip to content
Myr

index.js

This file

Path

examples/static-files/index.js

40 lines · 1.3 KiB · JavaScript

Last changed by

Merge pull request #2008 from agchou/clean-up-codeJonathan Ongbefore adoption2e830ff

History of this file

Take it

The walk stopped after 200 commits: lines older than 2e68ddb point at it.

Merge pull request #2008 from agchou/clean-up-codeJonathan Ongbefore adoption2e830ff

lines 1–3why, one step back
1/**
2 * Module dependencies.3 */

expose connect.middleware using Object.getOwnPropertyDescriptor()Jonathan Ongbefore adoption2e68ddb

lines 4–5why, one step back
4
5var express = require('../..');

remove last pieces of connect dependencyRoman Shtylmanbefore adoption1396e08

line 6why, one step back
6var logger = require('morgan');

expose connect.middleware using Object.getOwnPropertyDescriptor()Jonathan Ongbefore adoption2e68ddb

lines 7–9why, one step back
7var app = express();
89// log requests

remove last pieces of connect dependencyRoman Shtylmanbefore adoption1396e08

line 10why, one step back
10app.use(logger('dev'));

expose connect.middleware using Object.getOwnPropertyDescriptor()Jonathan Ongbefore adoption2e68ddb

lines 11–40why, one step back
11
12// express on its own has no notion13// of a "file". The express.static()14// middleware checks for a file matching15// the `req.path` within the directory16// that you pass it. In this case "GET /js/app.js"17// will look for "./public/js/app.js".1819app.use(express.static(__dirname + '/public'));2021// if you wanted to "prefix" you may use22// the mounting feature of Connect, for example23// "GET /static/js/app.js" instead of "GET /js/app.js".24// The mount-path "/static" is simply removed before25// passing control to the express.static() middleware,26// thus it serves the file correctly by ignoring "/static"27app.use('/static', express.static(__dirname + '/public'));2829// if for some reason you want to serve files from30// several directories, you can use express.static()31// multiple times! Here we're passing "./public/css",32// this will allow "GET /style.css" instead of "GET /css/style.css":33app.use(express.static(__dirname + '/public/css'));3435app.listen(3000);36console.log('listening on port 3000');37console.log('try:');38console.log(' GET /hello.txt');39console.log(' GET /js/app.js');40console.log(' GET /css/style.css');