-
Notifications
You must be signed in to change notification settings - Fork 17
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
Showing
7 changed files
with
250 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
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,33 @@ | ||
{ | ||
"servers": [ | ||
{ | ||
"port": 8080, | ||
"routes": [ | ||
{ | ||
"path": "/api", | ||
"methods": ["GET"], | ||
"handler": "./respond-with-message", | ||
"options": { | ||
"message": "GET at /api" | ||
} | ||
}, | ||
{ | ||
"path": "/api", | ||
"methods": ["POST"], | ||
"handler": "./respond-with-message", | ||
"options": { | ||
"message": "POST at /api" | ||
} | ||
}, | ||
{ | ||
"path": "*", | ||
"methods": "any", | ||
"handler": "./respond-with-message", | ||
"options": { | ||
"message": "any other request" | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} |
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,15 @@ | ||
{ | ||
"name": "frock-example-routing-in-the-frockfile", | ||
"version": "1.0.0", | ||
"description": "frock example showing routing in the frockfile", | ||
"main": "respond-with-message.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"frock": "frock" | ||
}, | ||
"author": "Urban Airship <web-team@urbanairship.com>", | ||
"license": "Apache-2.0", | ||
"devDependencies": { | ||
"frock": "^1.0.1" | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
docs/examples/routing-in-the-frockfile/respond-with-message.js
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,13 @@ | ||
module.exports = createPlugin | ||
|
||
function createPlugin (frock, logger, _options) { | ||
var options = _options || {} | ||
var message = options.message || 'no message provided' | ||
|
||
return handler | ||
|
||
function handler (req, res) { | ||
res.setHeader('content-type', 'text/plain') | ||
res.end(message) | ||
} | ||
} |
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,19 @@ | ||
{ | ||
"servers": [ | ||
{ | ||
"port": 8080, | ||
"routes": [ | ||
{ | ||
"path": "/mount-a/*", | ||
"methods": ["GET"], | ||
"handler": "./index-one-two" | ||
}, | ||
{ | ||
"path": "/mount-b/*", | ||
"methods": ["GET"], | ||
"handler": "./index-one-two" | ||
} | ||
] | ||
} | ||
] | ||
} |
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,27 @@ | ||
module.exports = createPlugin | ||
|
||
function createPlugin (frock, logger, options) { | ||
var router = frock.router(defaultRoute) | ||
|
||
router.get('one', one) | ||
router.get('two', two) | ||
router.get('^$', index) | ||
|
||
return router | ||
|
||
function one (req, res) { | ||
res.end('one!') | ||
} | ||
|
||
function two (req, res) { | ||
res.end('two!') | ||
} | ||
|
||
function index (req, res) { | ||
res.end('index!') | ||
} | ||
} | ||
|
||
function defaultRoute (req, res) { | ||
res.e404('no route configured') | ||
} |
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,15 @@ | ||
{ | ||
"name": "frock-example-routing-sub-routes", | ||
"version": "1.0.0", | ||
"description": "frock example showing routing in sub-routes", | ||
"main": "index-one-two.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"frock": "frock" | ||
}, | ||
"author": "Urban Airship <web-team@urbanairship.com>", | ||
"license": "Apache-2.0", | ||
"devDependencies": { | ||
"frock": "^1.0.1" | ||
} | ||
} |