forked from socketstream/socketstream
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Owen Barnes
committed
Jun 20, 2011
1 parent
12aded5
commit d409557
Showing
15 changed files
with
224 additions
and
134 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
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
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
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
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
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
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,48 @@ | ||
# HTTP Middleware Manager | ||
# ----------------------- | ||
# Loads custom and internal middleware | ||
|
||
util = require('util') | ||
copy = require('../utils/copy.coffee') | ||
|
||
# Define the stack | ||
stack = [] | ||
|
||
# Load HTTP middleware stack | ||
exports.init = -> | ||
loadCustom() | ||
load('url_parser') # must run first - required by other modules | ||
load('api') if SS.config.api.enabled | ||
load('browser_check') if SS.config.browser_check.enabled | ||
load('compile') if !SS.config.pack_assets | ||
load('static') # always serve static files last | ||
|
||
# Manage callback hell | ||
exports.execute = (request, response, i = 0) -> | ||
stack[i].call request, response, -> | ||
exports.execute(request, response, i + 1) | ||
|
||
|
||
# PRIVATE METHODS | ||
|
||
# Load custom HTTP config file and any custom middleware first | ||
loadCustom = -> | ||
file = "/config/http.coffee" | ||
try | ||
custom_http_handler = require("#{SS.root}#{file}") | ||
stack.push custom_http_handler | ||
catch e | ||
util.log "#{file} file missing! Attempting to copy default template..." | ||
source = __dirname + '/../../new_project/config/http.coffee' | ||
destination = "#{SS.root}/config/http.coffee" | ||
copy.copyFile source, destination | ||
util.log "#{file} file created!" | ||
|
||
# Load Internal Middleware | ||
load = (name) -> | ||
try | ||
stack.push processor = require("./#{name}.coffee") | ||
catch e | ||
unless processor | ||
SS.log.error.message "Unable to load internal HTTP middleware: #{name}" | ||
throw e |
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
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,17 @@ | ||
# Middleware: URL Parser | ||
# ---------------------- | ||
# Parses incoming URL into file extension, initial dir etc and adds this object to request.parsedURL for use later on | ||
|
||
exports.call = (request, response, next) -> | ||
raw = request.url | ||
[no_params, params] = raw.split('?') | ||
[url, extension] = no_params.split('.') | ||
[ignore, initialDir, actions...] = url.split('/') | ||
request.ss.parsedURL = | ||
extension: (if extension and extension != '/' then extension.toLowerCase() else null) | ||
initialDir: (if initialDir then initialDir.toLowerCase() else null) | ||
actions: (actions || null) | ||
params: (params || null) | ||
path: (if actions.length > 0 then [actions.join('/'), extension].join('.') else '') | ||
isRoot: (u = url.split('?')[0].split('/'); u.length == 2 and !raw.split('?')[0].match(/\./)) | ||
next() |
Empty file.
Oops, something went wrong.