mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Merge branch 'document-rest' into devel
Conflicts: docs/.meteor/versions
This commit is contained in:
@@ -29,7 +29,7 @@ Meteor is two things:
|
||||
* A _library of packages_: pre-written, self-contained modules that
|
||||
you might need in your app.<br>
|
||||
There are about a dozen core Meteor
|
||||
packages that most any app will use (for example `webapp`, which
|
||||
packages that most any app will use (for example [`webapp`](#webapp), which
|
||||
handles incoming HTTP connections, and `templating`, which lets you
|
||||
make HTML templates that automatically update live as data changes).
|
||||
Then there are optional packages like `email`, which lets your app
|
||||
|
||||
@@ -402,7 +402,8 @@ var toc = [
|
||||
"spiderable",
|
||||
"stylus",
|
||||
"showdown",
|
||||
"underscore"
|
||||
"underscore",
|
||||
"webapp"
|
||||
] ],
|
||||
|
||||
"Command line", [ [
|
||||
|
||||
@@ -36,6 +36,7 @@ Meteor Development Group maintains the following packages:
|
||||
{{> pkg_stylus}}
|
||||
{{> pkg_showdown}}
|
||||
{{> pkg_underscore}}
|
||||
{{> pkg_webapp}}
|
||||
|
||||
{{/markdown}}
|
||||
</template>
|
||||
|
||||
47
docs/client/packages/webapp.html
Normal file
47
docs/client/packages/webapp.html
Normal file
@@ -0,0 +1,47 @@
|
||||
<template name="pkg_webapp">
|
||||
{{#markdown}}
|
||||
## `webapp`
|
||||
|
||||
The `webapp` package is what lets your Meteor app serve content to a web
|
||||
browser. It is included in the `meteor-platform` set of packages that is
|
||||
automatically added when you run `meteor create`. You can easily build a
|
||||
Meteor app without it - for example if you wanted to make a command-line
|
||||
tool that still used the Meteor package system and DDP.
|
||||
|
||||
This package also allows you to add handlers for HTTP requests.
|
||||
This lets other services access your app's data through an HTTP API, allowing
|
||||
it to easily interoperate with tools and frameworks that don't yet support DDP.
|
||||
|
||||
`webapp` exposes the [connect](https://github.com/senchalabs/connect) API for
|
||||
handling requests through `WebApp.connectHandlers`.
|
||||
Here's an example that will let you handle a specific URL:
|
||||
|
||||
```js
|
||||
// Listen to incoming HTTP requests, can only be used on the server
|
||||
WebApp.connectHandlers.use("/hello", function(req, res, next) {
|
||||
res.writeHead(200);
|
||||
res.end("Hello world from: " + Meteor.release);
|
||||
});
|
||||
```
|
||||
|
||||
`WebApp.connectHandlers.use([path], handler)` has two arguments:
|
||||
|
||||
**path** - an optional path field.
|
||||
This handler will only be called on paths that match
|
||||
this string. The match has to border on a `/` or a `.`. For example, `/hello`
|
||||
will match `/hello/world` and `/hello.world`, but not `/hello_world`.
|
||||
|
||||
**handler** - this is a function that takes three arguments:
|
||||
|
||||
- **req** - a Node.js
|
||||
[IncomingMessage](http://nodejs.org/api/http.html#http_http_incomingmessage)
|
||||
object with some extra properties. This argument can be used to get information
|
||||
about the incoming request.
|
||||
- **res** - a Node.js
|
||||
[ServerResponse](http://nodejs.org/api/http.html#http_class_http_serverresponse)
|
||||
object. Use this to write data that should be sent in response to the
|
||||
request, and call `res.end()` when you are done.
|
||||
- **next** - a function. Calling this function will pass on the handling of
|
||||
this request to the next relevant handler.
|
||||
{{/markdown}}
|
||||
</template>
|
||||
Reference in New Issue
Block a user