moving old projects from cold storage to git for possible revival
commit
e22c5abe6a
|
@ -0,0 +1,61 @@
|
|||
//////////////////////////////////
|
||||
// NODESCORE SERVER INSTALLATION
|
||||
//////////////////////////////////
|
||||
|
||||
// installation for server running
|
||||
// debian stable or testing OS
|
||||
// other systems see here:
|
||||
// https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
|
||||
|
||||
//////////////////////////////////
|
||||
|
||||
//////////////////////////////////
|
||||
// get nodejs dependencies
|
||||
|
||||
apt-get update
|
||||
apt-get install git-core curl build-essential openssl libssl-dev
|
||||
|
||||
//////////////////////////////////
|
||||
// grab and compile from source
|
||||
|
||||
mkdir -p /tmp/build/node && cd /tmp/build/node
|
||||
git clone https://github.com/joyent/node.git .
|
||||
git checkout v0.8.0
|
||||
|
||||
./configure --openssl-libpath=/usr/lib/ssl
|
||||
make
|
||||
make test
|
||||
make install
|
||||
node -v
|
||||
|
||||
//////////////////////////////////
|
||||
// server side thumnail dependencies
|
||||
phantomjs
|
||||
imagemagick
|
||||
|
||||
|
||||
//aptitude install python-qt4 libqt4-webkit python-pip
|
||||
//aptitude install xvfb xbase-clients xfonts-base libgtk2.0-0
|
||||
|
||||
// get nodescore dependencies
|
||||
|
||||
|
||||
// the node_modules dir should life in the require.path
|
||||
// ~/
|
||||
|
||||
sudo npm install socket.io jsdom jQuery xmlhttprequest node-static requirejs
|
||||
sudo npm -g install supervisor
|
||||
|
||||
sudo ln -s /usr/bin/nodejs /usr/bin/node
|
||||
sudo update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10
|
||||
|
||||
//////////////////////////////////
|
||||
// get nodescore
|
||||
|
||||
git clone git://gitorious.org/nodescore/nodescore.git nodescore
|
||||
|
||||
//////////////////////////////////
|
||||
//start server
|
||||
|
||||
cd nodescore
|
||||
node nodescore.js
|
|
@ -0,0 +1,685 @@
|
|||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
Unless otherwise indicated all the code in these subdirectories is
|
||||
released under the GNU General Public License. A copy of this license
|
||||
is included below as well as in the main .pdf document.
|
||||
|
||||
Rob Canning 2017
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
|
@ -0,0 +1,17 @@
|
|||
|
||||
|
||||
|
||||
|
||||
README
|
||||
flow:
|
||||
|
||||
cd ../code/magick
|
||||
|
||||
edit ./svg_gen.sh to specify instrument and target location
|
||||
|
||||
./svg_gen.sh
|
||||
|
||||
for f in *.svg ; do mv $f ${f#???}; done
|
||||
|
||||
count=0 ;for i in [0-7]*.svg ; do count=$((count+1)) ; echo mv $i $count.svg ; done
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
# NODESCORE: A netscore playout server.
|
||||
|
||||
## NODESCORE SERVER INSTALLATION
|
||||
installation for server running debian stable or testing OS other systems see here: https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
|
||||
|
||||
### get nodejs dependencies
|
||||
```
|
||||
apt-get update
|
||||
apt-get install git-core curl build-essential openssl libssl-dev
|
||||
```
|
||||
//////////////////////////////////
|
||||
// grab and compile from source
|
||||
```
|
||||
mkdir -p /tmp/build/node && cd /tmp/build/node
|
||||
git clone https://github.com/joyent/node.git .
|
||||
git checkout v0.8.0
|
||||
./configure --openssl-libpath=/usr/lib/ssl
|
||||
make
|
||||
make test
|
||||
make install
|
||||
node -v
|
||||
```
|
||||
### install server-side dependencies
|
||||
```
|
||||
aptitude install phantomjs
|
||||
aptitude install imagemagick
|
||||
aptitude install python-qt4 libqt4-webkit python-pip
|
||||
aptitude install xvfb xbase-clients xfonts-base libgtk2.0-0
|
||||
// get nodescore dependencies
|
||||
// the node_modules dir should live in the require.path
|
||||
sudo npm install socket.io jsdom jQuery xmlhttprequest node-static requirejs
|
||||
sudo npm -g install supervisor
|
||||
sudo ln -s /usr/bin/nodejs /usr/bin/node
|
||||
sudo update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10
|
||||
```
|
||||
|
||||
### install nodescore
|
||||
git clone git@git.kiben.net:rc/nodescore.git
|
||||
### start server
|
||||
```
|
||||
cd nodescore
|
||||
node nodescore.js
|
||||
```
|
||||
|
||||
## generating material from old magick system and importing to nodescore:
|
||||
|
||||
flow:
|
||||
|
||||
cd ../code/magick
|
||||
|
||||
edit ./svg_gen.sh to specify instrument and target location
|
||||
|
||||
./svg_gen.sh
|
||||
|
||||
for f in *.svg ; do mv $f ${f#???}; done
|
||||
|
||||
count=0 ;for i in [0-7]*.svg ; do count=$((count+1)) ; echo mv $i $count.svg ; done
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
CODE IS HERE:
|
||||
https://gitorious.org/nodescore
|
||||
|
||||
control interface is:
|
||||
http://nodescore.kiben.net:8889/m/c.html
|
||||
|
||||
score interface is:
|
||||
http://nodescore.kiben.net:8889/m/score.html
|
||||
|
||||
// NEEDS MODULARISATION
|
||||
|
||||
most stuff is in nodescore.js its a mess - everything is sending
|
||||
socket.broadcast.emit and socket.emit everything should be modular and
|
||||
return values which are sent from one of these socket.broadcast.*
|
||||
things - its just all too tangled up with this socket.on and socket broadcast stuff
|
||||
this is the main thing that needs tidying
|
||||
|
||||
|
||||
the scoreB.js file contains the sequncer/score duration/unit lists but
|
||||
that is about the only thing that is modularised.
|
||||
|
||||
i would like to have:
|
||||
the magicsquare sequencer section in one file
|
||||
the stopwatch / date time stuff in a file
|
||||
the webserver stuff in a serperate file
|
||||
the chat stuff in a seperate file
|
||||
the sockets stuff in a seperate file
|
||||
|
||||
all this called up in a minimal nodescore.js file using requirejs ? is this the best way
|
||||
|
||||
/// OLD SEQUENCERS WONT DIE ON RESET
|
||||
|
||||
BUG: on stop reset start the old instances of the sequencer remain so
|
||||
eventually they consume all the memory they should be cleaned
|
||||
up/deleted when the resetSeq function is called so there are never
|
||||
more than one set of
|
||||
seqA seqB seqC seqD instances called by:
|
||||
step(seqA);step(seqB); step(seqC); step(seqD);
|
||||
|
||||
|
||||
socket.on('resetSeq', function () {
|
||||
console.log("reset")
|
||||
resetChr();
|
||||
});
|
||||
|
||||
|
||||
//==========================
|
||||
SOCKET - CLIENT IDENTIFICATION IS DUMB
|
||||
the way the sockets work is really dumb at the moment
|
||||
|
||||
each client should only recieve stuff targeted at it specically using its socket id
|
||||
at the moment this is not done - all clients recieve all messages and filter them based on a
|
||||
|
||||
<input type="hidden" id="group" value='1'> which is set by the
|
||||
dropdown box [Stream 01-04] in the browser the clients only listen to
|
||||
their own group ID this is stupid but it works - not sure if causes
|
||||
congestion with all the extra messages flying around unnecessarily
|
||||
|
||||
// CLOCKS and METRO DRIFT
|
||||
at 60bpm ie a pulse every 1000ms then the chonometer and the
|
||||
metro/countdown timers should beat together - but they dont they drift
|
||||
apart - maybe there should be some common clock driving all the timing
|
||||
stuff rather than different setIntervals starting together
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// LATENCY COMPENSATION ISNT IMPLENTED YET
|
||||
// MORE MAGIC SQUARE ROUTES
|
||||
// MAGIC SQUARE ROUTE CHOOSING INTERFACE
|
|
@ -0,0 +1,321 @@
|
|||
/*
|
||||
////////////////////////////////////////////
|
||||
nodescore server
|
||||
nodescore.kiben.net
|
||||
nodescore@kiben.net
|
||||
////////////////////////////////////////////
|
||||
*/
|
||||
|
||||
var sio = require('socket.io')
|
||||
, http = require('http')
|
||||
, ch = require('./chronometer')
|
||||
, url = require('url')
|
||||
, path = require('path')
|
||||
, fs = require('fs')
|
||||
, connect = require('connect')
|
||||
, static = require('node-static');
|
||||
|
||||
var mimeTypes = {
|
||||
"html": "text/html",
|
||||
"jpeg": "image/jpeg",
|
||||
"jpg": "image/jpeg",
|
||||
"png": "image/png",
|
||||
"js": "text/javascript",
|
||||
"css": "text/css"};
|
||||
|
||||
var requirejs = require('requirejs');
|
||||
|
||||
requirejs.config({
|
||||
//Pass the top-level main.js/index.js require
|
||||
//function to requirejs so that node modules
|
||||
//are loaded relative to the top-level JS file.
|
||||
nodeRequire: require,
|
||||
findNestedDependencies: true
|
||||
});
|
||||
|
||||
var pinging=0
|
||||
console.log("ping set to 0")
|
||||
|
||||
// run webserver serving static html
|
||||
////////////////////////////////////////////
|
||||
var httpServer = connect()
|
||||
.use(connect.logger('dev'))
|
||||
.use(connect.static('www'))
|
||||
.use(function(req, res){
|
||||
res.end('404\n');
|
||||
})
|
||||
.listen(8890);
|
||||
|
||||
////////////////////////////////////////////
|
||||
// connect to websockets
|
||||
////////////////////////////////////////////
|
||||
|
||||
|
||||
io = sio.listen(httpServer)
|
||||
, nicknames = {};
|
||||
|
||||
//var sequencer = require('./sequencer')
|
||||
|
||||
io.set('log level', 4); // reduce logging
|
||||
io.sockets.on('connection', function (socket) {
|
||||
|
||||
socket.on('nickname', function (nick, fn) {
|
||||
if (nicknames[nick]) {
|
||||
fn(true);
|
||||
} else {
|
||||
fn(false);
|
||||
nicknames[nick] = socket.nickname = nick;
|
||||
socket.broadcast.emit('announcement', nick + ' connected');
|
||||
io.sockets.emit('nicknames', nicknames);
|
||||
}
|
||||
});
|
||||
|
||||
/// chat user messages to screens and to log file
|
||||
// date format for filename
|
||||
var da = new Date(); var dtstring = da.getFullYear()+ '-' + da.getMonth()+ '-' + da.getDate();
|
||||
////////////////////////
|
||||
/// log messages to file
|
||||
socket.on('user message', function (msg) {
|
||||
fs.open('logs/chatlog-'+dtstring+'.txt', 'a', 666, function( e, id ) {
|
||||
//time format for message stamp
|
||||
var dt = new Date();var timestring = dt.getHours() + ':' + dt.getMinutes() + ':' + dt.getSeconds();
|
||||
socket.broadcast.emit('user message', socket.nickname, msg);
|
||||
var fs = require('fs'), str = msg;
|
||||
fs.write( id, timestring+" " + socket.nickname + ": "+ msg+"\n", null, 'utf8', function(){});
|
||||
});
|
||||
});
|
||||
|
||||
////////////////////////////////////////////
|
||||
// chronometer + sequencer controls (all this should be modularised)
|
||||
////////////////////////////////////////////
|
||||
|
||||
socket.on('stopWatch', function (state) { stopWatch(state);});
|
||||
socket.on('stopChr', function () { stopChr(); });
|
||||
socket.on('resetChr', function () { resetChr();});
|
||||
socket.on('startSeq', function () { startChr(); });
|
||||
var chronstate=0;
|
||||
|
||||
// send the date/time every second
|
||||
|
||||
xdatetime = setInterval(function () {
|
||||
d = ch.xdateTime()
|
||||
socket.broadcast.emit('dateTime', d)
|
||||
socket.emit('dateTime', d)
|
||||
}, 1000)
|
||||
|
||||
//////////////////////////////
|
||||
// /* this should be moved to its own file chronometer.js
|
||||
|
||||
function chronCtrl (state,interval){
|
||||
if (state==1){ console.log("chronControl....onestate")
|
||||
var date = new Date(); var starttime = new Date().getTime() / 1000;
|
||||
xstopwatch = setInterval(function () {
|
||||
var nowtime = new Date().getTime() / 1000;
|
||||
now = nowtime-starttime
|
||||
hours = parseInt( now / 3600 ) % 24;
|
||||
minutes = parseInt( now / 60 ) % 60;
|
||||
seconds = parseInt(now % 60);
|
||||
milliseconds = Math.floor((now-seconds)*10)%60;
|
||||
time =
|
||||
(hours < 10 ? "0" + hours : hours) + ":" +
|
||||
(minutes < 10 ? "0" + minutes : minutes) + ":" +
|
||||
(seconds < 10 ? "0" + seconds : seconds) + "."+
|
||||
milliseconds;
|
||||
socket.broadcast.emit('chronFromServer', time)
|
||||
socket.emit('chronFromServer', time)
|
||||
}, 100)
|
||||
}
|
||||
|
||||
if (state==0) { console.log("chronControl....zerostate") ; clearInterval(xstopwatch); }
|
||||
|
||||
}
|
||||
|
||||
|
||||
// if not already started start the chronometer and sequencer
|
||||
function startChr(socket) { chronCtrl(1,100); step(seqA);step(seqB); step(seqC); step(seqD); }
|
||||
// stop the chronometer
|
||||
function stopChr() { console.log("stop chron"); chronCtrl(0); }
|
||||
|
||||
function pad(number) { return (number < 10 ? '0' : '') + number }
|
||||
function resetChr() {//clearInterval();
|
||||
zecsec = 0; seconds = 0; mins = 0; hours = 0;
|
||||
var chron = pad(hours) +":"+pad(mins)+ ':'+ pad(seconds)+ ":"+ zecsec
|
||||
// send 0.00.00 values to display
|
||||
socket.broadcast.emit('chronFromServer', chron)
|
||||
socket.emit('chronFromServer', chron)
|
||||
}
|
||||
|
||||
////////////////////////////////////////////
|
||||
// magic square sequencer (this should be modularised)
|
||||
////////////////////////////////////////////
|
||||
// all the variables this sequencer needs are in scoreB.js
|
||||
requirejs(['scoreB'],function(scoreB) {});
|
||||
|
||||
var sequencerState=0;
|
||||
var numberoftransects=3
|
||||
var order=8
|
||||
var countdowntick=function(seq){
|
||||
var unit=seq.units[seq.transect%numberoftransects][seq.counter];
|
||||
var unitlast=seq.units[seq.transect%numberoftransects][seq.counter-1];
|
||||
var voice=seq.voice;
|
||||
var tempoms = Math.floor(60000/seq.mm)
|
||||
var timemultiplier=1000
|
||||
var outcount=4; var incount=4;
|
||||
var dur=srcsqr[Math.floor(unit/order)][unit%order] + 4
|
||||
var time = dur;
|
||||
var ztime=time;
|
||||
var totaltime=time
|
||||
initPage=function(seq){
|
||||
// initiate first page here
|
||||
socket.emit("pageIni", voice, unit, time, seq.mm,seq.counter,seq.nextunit );
|
||||
socket.emit("pageFlipfromserver", voice, unit, time, seq.mm,seq.counter,seq.nextunit );
|
||||
}
|
||||
|
||||
function sequenCer() {
|
||||
if (ztime >= 0 ){
|
||||
var counter = ztime
|
||||
// flip the page
|
||||
if (counter == 0){
|
||||
//increment the row position
|
||||
seq.counter = (seq.counter + 1) % (order)
|
||||
//increment the transect
|
||||
if ( seq.counter==0 ){ seq.transect += 1 }
|
||||
socket.broadcast.emit("pageFlipfromserver", voice, unit, time, seq.mm,seq.counter,seq.nextunit);
|
||||
clearInterval(pulse)
|
||||
step(seq);
|
||||
}
|
||||
|
||||
if (counter >= 0 ){
|
||||
socket.broadcast.emit('counterText',
|
||||
voice, unit, counter,seq.counter,unitlast,seq.transect%numberoftransects);
|
||||
socket.emit('counterText',
|
||||
voice, unit, counter,seq.counter,unitlast,seq.transect%numberoftransects);
|
||||
|
||||
if (counter <= outcount ) {
|
||||
socket.broadcast.emit('countinFromServer',
|
||||
voice, counter,
|
||||
"","stop in: ", "red", "transparent",unit);
|
||||
socket.emit('countinFromServer',
|
||||
voice, counter,
|
||||
"","stop in: ", "red", "transparent",unit);
|
||||
}
|
||||
|
||||
if (counter > (totaltime)-incount && counter <= totaltime ) {
|
||||
socket.broadcast.emit('countinFromServer',
|
||||
voice, counter-(totaltime-incount),
|
||||
"","play in: ", "green","transparent",unit);
|
||||
socket.emit('countinFromServer',
|
||||
voice,counter-(totaltime-incount),
|
||||
"","play in: ", "green","transparent",unit);
|
||||
}
|
||||
|
||||
if (counter == (totaltime)-incount ) {
|
||||
socket.broadcast.emit('countinFromServer',
|
||||
voice, "+",
|
||||
"","playing.. ", "green","transparent",unit);
|
||||
socket.emit('countinFromServer',
|
||||
voice, "+",
|
||||
"","playing.. ", "green","transparent",unit);
|
||||
}
|
||||
}
|
||||
|
||||
// on each beat do:
|
||||
// push out the pulse to metronome
|
||||
seq.metrobeat = (seq.metrobeat+1)%seq.beatsinbar ;
|
||||
socket.broadcast.emit('metroPulse', tempoms, voice,seq.metrobeat);
|
||||
socket.emit('metroPulse', tempoms, voice, seq.metrobeat);
|
||||
}
|
||||
|
||||
// decrement the time
|
||||
ztime -= 1
|
||||
|
||||
// this shows undefined counter output - bug related
|
||||
// console.log(counter)
|
||||
}
|
||||
|
||||
var pulse = setInterval(sequenCer, tempoms);
|
||||
|
||||
socket.on('stopSeq', function () {
|
||||
sequenCer.clearInterval
|
||||
console.log("sequencer stopping...")
|
||||
// grrr why wont this clearInterval work
|
||||
sequencerState = 0
|
||||
clearInterval(pulse)
|
||||
sequenCer.clearInterval(pulse)
|
||||
stopChr();
|
||||
});
|
||||
};
|
||||
|
||||
step = function (seq) {
|
||||
clearInterval(countdowntick);
|
||||
countdowntick(seq)
|
||||
sequencerState=1;
|
||||
initPage(seq)
|
||||
};
|
||||
|
||||
socket.on('resetSeq', function () { resetChr(); });
|
||||
|
||||
////////////////////////////////////////////
|
||||
// some latency calculations
|
||||
///////////////////////////////////////////
|
||||
|
||||
/*
|
||||
a ping is periodically broadcast to all connected clients each
|
||||
connected returns a pong to the server via an "emit" and in turn
|
||||
the server returns each unique client a report of the latency
|
||||
via another emit - the emit only sends to the source of the
|
||||
request, whereas the broadcast.emit.. broadcasts.. ie to all
|
||||
connected clients
|
||||
|
||||
TODO: smooth range and average out results to remove erratic ping
|
||||
times.
|
||||
|
||||
TODO:
|
||||
The result then needs to be used to stagger outgoing messages to
|
||||
compensate for latency - how much compensation is more connected
|
||||
to the time that any audio/video feed needs to encode/decode as
|
||||
the latency of the route from node A to node B is inavoidable?!
|
||||
so maybe latency is irrelevant in this context - we just need to
|
||||
stagger signals according to encoding decoding times.. hmmm
|
||||
*/
|
||||
|
||||
|
||||
// periodically broadcast a ping
|
||||
function serverTime(freq) {
|
||||
if (pinging==0){ st = setInterval(function() {
|
||||
var pinging=1;
|
||||
var d = new Date(); var n = d.getTime();
|
||||
socket.emit("timeFromServer", n);
|
||||
}, 1000); } else console.log("already pinging")
|
||||
}
|
||||
// receive the pong calculate the latency and
|
||||
// return the response to the client
|
||||
|
||||
socket.on("clientTimeResponse", function(x) {
|
||||
var d = new Date(); var n = d.getTime();
|
||||
var latency = (n-x)/2;
|
||||
//console.log("SERVERTIME:"+x + " LATENCY:" + latency);
|
||||
socket.emit("latencyFromServer", latency);
|
||||
});
|
||||
|
||||
|
||||
|
||||
serverTime(1000);
|
||||
|
||||
socket.on('disconnect', function(client) {
|
||||
console.log(socket.nickname + " is gone..." )
|
||||
clearInterval(st);
|
||||
|
||||
if (!socket.nickname) return;
|
||||
|
||||
delete nicknames[socket.nickname];
|
||||
socket.broadcast.emit('announcement', socket.nickname + ' disconnected');
|
||||
socket.broadcast.emit('nicknames', nicknames);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
exports.socket= io.sockets;
|
||||
exports.httpServer = httpServer;
|
||||
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
////////////////////////////////////////////
|
||||
// Chronometer
|
||||
////////////////////////////////////////////
|
||||
|
||||
// number padding: 0 to 00
|
||||
function pad(number) { return (number < 10 ? '0' : '') + number }
|
||||
|
||||
function xdateTime() {
|
||||
var xdatetime= new Date();
|
||||
var now=xdatetime.toString()
|
||||
return now
|
||||
}
|
||||
|
||||
|
||||
// the chronometer initial states
|
||||
function zeroChron(){
|
||||
zecsec = 0; seconds = 0;
|
||||
mins = 0; hours = 0;
|
||||
zero = pad(hours) +":"+pad(mins)+ ':'+ pad(seconds)
|
||||
chron = zero
|
||||
return zero
|
||||
}
|
||||
|
||||
zeroChron()
|
||||
|
||||
/*
|
||||
function chronCtrl (state,interval){
|
||||
console.log("=========================== chronstate=" + state)
|
||||
if (state==1){
|
||||
var date = new Date()
|
||||
var starttime = new Date().getTime() / 1000;
|
||||
//var interval = 1020 - date.getMilliseconds();
|
||||
xstopwatch = setInterval(function () {
|
||||
var nowtime = new Date().getTime() / 1000;
|
||||
now = nowtime-starttime
|
||||
hours = parseInt( now / 3600 ) % 24;
|
||||
minutes = parseInt( now / 60 ) % 60;
|
||||
seconds = parseInt(now % 60);
|
||||
milliseconds = Math.floor((now-seconds)*10)%60;
|
||||
time = (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds < 10 ? "0" + seconds : seconds) + "."+milliseconds;
|
||||
console.log(time)
|
||||
// socket.broadcast.emit('chronFromServer', time)
|
||||
// socket.emit('chronFromServer', time)
|
||||
}, 100)
|
||||
}
|
||||
if (state==0) {
|
||||
clearInterval(xstopwatch);
|
||||
}
|
||||
}
|
||||
*/
|
||||
//exports.chronCtrl = chronCtrl;
|
||||
exports.xdateTime = xdateTime;
|
||||
exports.zeroChron = zeroChron;
|
|
@ -0,0 +1,20 @@
|
|||
#!/bin/bash
|
||||
|
||||
src="/home/rob/code/nodescore/www/8/svg/"
|
||||
|
||||
cd ../magick/
|
||||
|
||||
#./create_svg.py --output=emma --sections=1 --instrument=emma
|
||||
|
||||
cp /var/www/magick.kiben.net/m/output/emma/svg/*.svg $src
|
||||
|
||||
cd $src
|
||||
|
||||
for f in *.svg ; do mv $f ${f#???}; done
|
||||
count=-1 ;for i in [0-7]*.svg ; do count=$((count+1)) ;mv $i $count.svg ; done
|
||||
|
||||
cd /home/rob/code/nodescore
|
||||
|
||||
./svgmods.sh
|
||||
./musicfilegenerator.sh
|
||||
./ss2thumb.sh
|
|
@ -0,0 +1,17 @@
|
|||
#!/bin/sh
|
||||
|
||||
#sudo dpkg-reconfigure dash
|
||||
# use bash instead of dash on ubuntu systems
|
||||
|
||||
#sudo apt-get install phantomjs supervisor
|
||||
#npm install sockets.io node-static requirejs
|
||||
|
||||
mkdir -p /usr/local/bin
|
||||
cp -pa nodescore /usr/local/bin/
|
||||
|
||||
mkdir /usr/share/nodescore
|
||||
cp -pa www *.js /usr/share/nodescore/
|
||||
chown -R rob:www-data /usr/share/nodescore/
|
||||
cp -pa nodescored /etc/init.d/
|
||||
chmod 755 /etc/init.d/nodescored
|
||||
update-rc.d nodescored defaults
|
|
@ -0,0 +1,170 @@
|
|||
15:19:2 howdy: sdf
|
||||
15:19:3 howdy: a
|
||||
15:19:4 howdy: f
|
||||
15:19:4 howdy: d
|
||||
15:19:23 howdy: asdad
|
||||
15:24:50 s: s
|
||||
15:24:51 s: s
|
||||
15:24:53 s: s
|
||||
15:24:59 s: s
|
||||
15:25:0 s: s
|
||||
15:25:1 s: s
|
||||
15:25:1 s: s
|
||||
15:25:2 s: s
|
||||
15:25:2 s: s
|
||||
15:25:2 s: s
|
||||
15:25:3 s: s
|
||||
15:25:12 s: we
|
||||
15:25:13 s: sds
|
||||
15:25:13 s: dsd
|
||||
15:25:14 s: sd
|
||||
15:26:30 asd: a
|
||||
15:26:31 asd: s
|
||||
15:26:31 asd: s
|
||||
15:28:8 asd: asd
|
||||
15:28:8 asd: asd
|
||||
15:28:9 asd: s
|
||||
15:28:9 asd: s
|
||||
15:28:9 asd: s
|
||||
15:28:9 asd: s
|
||||
15:28:10 asd: s
|
||||
15:28:10 asd: s
|
||||
15:28:10 asd: s
|
||||
15:28:10 asd: s
|
||||
15:29:26 asd: j
|
||||
15:31:5 fadf: ddddddddddddddddddddddddddddddddddd
|
||||
15:31:6 fadf: d
|
||||
15:31:6 fadf:
|
||||
15:31:7 fadf: d
|
||||
15:31:7 fadf:
|
||||
15:31:7 fadf:
|
||||
15:31:7 fadf:
|
||||
15:31:7 fadf:
|
||||
15:31:8 fadf: d
|
||||
15:32:1 asdf: how does tis work for you
|
||||
15:32:14 asdf: we can only asdfasdfasdf asdfa sdfasdf
|
||||
15:33:14 asdf: ASD
|
||||
20:11:41 asd: asd
|
||||
20:11:41 asd: s
|
||||
20:11:41 asd: s
|
||||
20:11:42 asd: s
|
||||
20:11:42 asd: ss
|
||||
20:11:42 asd: s
|
||||
20:11:42 asd: s
|
||||
20:11:43 asd: s
|
||||
20:11:43 asd: s
|
||||
20:11:43 asd: s
|
||||
20:11:43 asd: s
|
||||
20:11:43 asd: s
|
||||
20:11:44 asd: s
|
||||
20:11:44 asd: s
|
||||
20:11:44 asd: s
|
||||
20:11:44 asd: s
|
||||
20:11:44 asd: sss
|
||||
20:14:3 sdf: sdf
|
||||
20:14:4 sdf: sdfdd
|
||||
20:14:4 sdf: d
|
||||
20:14:5 sdf:
|
||||
20:14:5 sdf: d
|
||||
20:14:5 sdf: d
|
||||
20:14:5 sdf: d
|
||||
20:14:6 sdf: d
|
||||
20:14:6 sdf:
|
||||
20:14:6 sdf: d
|
||||
20:14:6 sdf:
|
||||
20:14:6 sdf: dd
|
||||
20:14:30 sdf: a
|
||||
20:14:31 sdf: a
|
||||
20:14:37 sdf: A
|
||||
20:14:37 sdf: A
|
||||
20:14:37 sdf: A
|
||||
20:14:38 sdf: A
|
||||
20:14:38 sdf: A
|
||||
20:14:38 sdf: A
|
||||
20:14:40 sdf: A
|
||||
20:14:52 S: A
|
||||
20:14:53 S:
|
||||
20:14:53 S: A
|
||||
20:28:17 s: sdf
|
||||
20:28:29 s: well how does tus work for you
|
||||
20:32:2 a: sdf
|
||||
20:32:3 a: s
|
||||
20:32:5 a: sa
|
||||
20:37:40 fg: i am thinking of stopping soon
|
||||
20:40:0 asd: asd
|
||||
20:40:0 asd: \
|
||||
20:40:1 asd:
|
||||
20:40:1 asd: asd
|
||||
20:40:2 asd: asd
|
||||
20:40:2 asd: a
|
||||
20:40:3 asd: s
|
||||
20:40:3 asd: s
|
||||
20:40:3 asd: s
|
||||
20:41:23 sdf:
|
||||
20:41:24 sdf: sdf
|
||||
20:41:25 sdf: sdf
|
||||
20:41:26 sdf: sdf
|
||||
20:41:26 sdf: sdf
|
||||
20:41:26 sdf: sdf
|
||||
20:41:27 sdf: sdf
|
||||
20:41:27 sdf: sdf
|
||||
20:41:27 sdf:
|
||||
20:41:28 sdf: sdf
|
||||
20:41:58 aa: a
|
||||
20:41:59 aa: aa
|
||||
20:41:59 aa: a
|
||||
20:42:0 aa: a
|
||||
20:42:0 aa: a
|
||||
20:42:0 aa: aa
|
||||
20:42:37 sdf: sdf
|
||||
20:42:39 sdf: sdf
|
||||
20:43:34 asdf: yellow what is t
|
||||
20:43:38 asdf: sdf
|
||||
20:43:39 asdf: sdf
|
||||
20:43:39 asdf: sf
|
||||
20:43:40 asdf:
|
||||
20:43:51 asdf: s
|
||||
20:43:51 asdf: s
|
||||
20:43:52 asdf: s
|
||||
20:43:52 asdf: s
|
||||
20:43:52 asdf: s
|
||||
20:43:52 asdf: s
|
||||
20:43:52 asdf: s
|
||||
20:43:53 asdf: s
|
||||
20:43:53 asdf: s
|
||||
20:43:53 asdf:
|
||||
20:43:53 asdf: s
|
||||
20:43:54 asdf: s
|
||||
20:43:54 asdf: s
|
||||
20:43:54 asdf: s
|
||||
20:43:54 asdf: s
|
||||
20:43:54 asdf: s
|
||||
20:43:55 asdf: s
|
||||
20:43:55 asdf: s
|
||||
20:43:55 asdf: s
|
||||
20:43:55 asdf: s
|
||||
20:43:55 asdf: s
|
||||
20:43:56 asdf: s
|
||||
20:43:56 asdf: s
|
||||
20:43:56 asdf: s
|
||||
20:43:56 asdf: s
|
||||
20:43:56 asdf: s
|
||||
20:43:57 asdf: s
|
||||
20:43:58 asdf: ss
|
||||
20:53:54 a: sdf
|
||||
20:54:48 asd:
|
||||
20:54:49 asd: asd
|
||||
20:55:28 sdf: sdf
|
||||
20:55:29 sdf: sd
|
||||
20:55:29 sdf: d
|
||||
20:55:29 sdf: d
|
||||
20:55:29 sdf: d
|
||||
20:55:30 sdf: d
|
||||
20:55:38 sdf: dljasd
|
||||
20:56:42 s: s
|
||||
20:56:43 s: s
|
||||
20:56:43 s: s
|
||||
20:56:43 s: s
|
||||
20:56:45 s: ss
|
||||
22:37:22 asd: howdy
|
||||
22:39:58 undefined:
|
|
@ -0,0 +1,9 @@
|
|||
13:41:33 asdf: sdf
|
||||
13:41:34 asdf: asdf
|
||||
13:41:34 asdf: asdf
|
||||
13:41:35 asdf: asd
|
||||
13:46:33 AS: A
|
||||
13:46:39 AS: THIS IS THE CHAT
|
||||
14:13:0 rob: aasdf
|
||||
14:13:1 rob: adf
|
||||
14:16:24 asd: this is a message
|
|
@ -0,0 +1,14 @@
|
|||
9:9:56 undefined: sfd
|
||||
11:54:35 asdf: ASD
|
||||
11:59:53 a: a
|
||||
11:59:54 a: a
|
||||
13:41:10 undefined: sdf
|
||||
13:41:16 sdf: sdfsdf
|
||||
13:41:17 sdf: sdf
|
||||
13:41:18 sdf: sdf
|
||||
13:42:49 sdf: aaa
|
||||
13:52:36 undefined: efsd
|
||||
22:41:0 asd: asdf
|
||||
22:41:5 asd: asdf
|
||||
22:53:2 asd: jjhgj
|
||||
22:53:4 asd: juh
|
|
@ -0,0 +1,3 @@
|
|||
16:24:1 rob: sdfsdf
|
||||
16:24:2 rob: sdsfsdf
|
||||
16:24:3 rob: sdfds
|
|
@ -0,0 +1,6 @@
|
|||
18:46:25 asd: as
|
||||
18:46:26 asd: as
|
||||
18:46:27 asd: as
|
||||
18:46:27 asd: as
|
||||
18:46:28 asd: as
|
||||
22:47:12 sdf: sdf
|
|
@ -0,0 +1,3 @@
|
|||
coverage/
|
||||
test/
|
||||
.travis.yml
|
|
@ -0,0 +1,32 @@
|
|||
1.1.1 / 2014-06-20
|
||||
==================
|
||||
|
||||
* deps: accepts@~1.0.4
|
||||
- use `mime-types`
|
||||
|
||||
1.1.0 / 2014-06-16
|
||||
==================
|
||||
|
||||
* Display error on console formatted like `throw`
|
||||
* Escape HTML with `escape-html` module
|
||||
* Escape HTML in stack trace
|
||||
* Escape HTML in title
|
||||
* Fix up edge cases with error sent in response
|
||||
* Set `X-Content-Type-Options: nosniff` header
|
||||
* Use accepts for negotiation
|
||||
|
||||
1.0.2 / 2014-06-05
|
||||
==================
|
||||
|
||||
* Pass on errors from reading error files
|
||||
|
||||
1.0.1 / 2014-04-29
|
||||
==================
|
||||
|
||||
* Clean up error CSS
|
||||
* Do not respond after headers sent
|
||||
|
||||
1.0.0 / 2014-03-03
|
||||
==================
|
||||
|
||||
* Genesis from `connect`
|
|
@ -0,0 +1,59 @@
|
|||
# errorhandler
|
||||
|
||||
[![NPM version](https://badge.fury.io/js/errorhandler.svg)](http://badge.fury.io/js/errorhandler)
|
||||
[![Build Status](https://travis-ci.org/expressjs/errorhandler.svg?branch=master)](https://travis-ci.org/expressjs/errorhandler)
|
||||
[![Coverage Status](https://img.shields.io/coveralls/expressjs/errorhandler.svg?branch=master)](https://coveralls.io/r/expressjs/errorhandler)
|
||||
|
||||
Previously `connect.errorHandler()`.
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
$ npm install errorhandler
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### errorhandler()
|
||||
|
||||
Create new middleware to handle errors and respond with content negotiation.
|
||||
This middleware is only intended to be used in a development environment, as
|
||||
the full error stack traces will be send back to the client when an error
|
||||
occurs.
|
||||
|
||||
## Example
|
||||
|
||||
```js
|
||||
var connect = require('connect')
|
||||
var errorhandler = require('errorhandler')
|
||||
|
||||
var app = connect()
|
||||
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
app.use(errorhandler())
|
||||
}
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Jonathan Ong me@jongleberry.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
|
@ -0,0 +1,111 @@
|
|||
/*!
|
||||
* errorhandler
|
||||
* Copyright(c) 2010 Sencha Inc.
|
||||
* Copyright(c) 2011 TJ Holowaychuk
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var accepts = require('accepts')
|
||||
var escapeHtml = require('escape-html');
|
||||
var fs = require('fs');
|
||||
|
||||
/**
|
||||
* Error handler:
|
||||
*
|
||||
* Development error handler, providing stack traces
|
||||
* and error message responses for requests accepting text, html,
|
||||
* or json.
|
||||
*
|
||||
* Text:
|
||||
*
|
||||
* By default, and when _text/plain_ is accepted a simple stack trace
|
||||
* or error message will be returned.
|
||||
*
|
||||
* JSON:
|
||||
*
|
||||
* When _application/json_ is accepted, connect will respond with
|
||||
* an object in the form of `{ "error": error }`.
|
||||
*
|
||||
* HTML:
|
||||
*
|
||||
* When accepted connect will output a nice html stack trace.
|
||||
*
|
||||
* @return {Function}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
exports = module.exports = function errorHandler(){
|
||||
// get environment
|
||||
var env = process.env.NODE_ENV || 'development'
|
||||
|
||||
return function errorHandler(err, req, res, next){
|
||||
// respect err.status
|
||||
if (err.status) {
|
||||
res.statusCode = err.status
|
||||
}
|
||||
|
||||
// default status code to 500
|
||||
if (res.statusCode < 400) {
|
||||
res.statusCode = 500
|
||||
}
|
||||
|
||||
// write error to console
|
||||
if (env !== 'test') {
|
||||
console.error(err.stack || String(err))
|
||||
}
|
||||
|
||||
// cannot actually respond
|
||||
if (res._header) {
|
||||
return req.socket.destroy()
|
||||
}
|
||||
|
||||
// negotiate
|
||||
var accept = accepts(req)
|
||||
var type = accept.types('html', 'json', 'text')
|
||||
|
||||
// Security header for content sniffing
|
||||
res.setHeader('X-Content-Type-Options', 'nosniff')
|
||||
|
||||
// html
|
||||
if (type === 'html') {
|
||||
fs.readFile(__dirname + '/public/style.css', 'utf8', function(e, style){
|
||||
if (e) return next(e);
|
||||
fs.readFile(__dirname + '/public/error.html', 'utf8', function(e, html){
|
||||
if (e) return next(e);
|
||||
var stack = (err.stack || '')
|
||||
.split('\n').slice(1)
|
||||
.map(function(v){ return '<li>' + escapeHtml(v).replace(/ /g, ' ') + '</li>'; }).join('');
|
||||
html = html
|
||||
.replace('{style}', style)
|
||||
.replace('{stack}', stack)
|
||||
.replace('{title}', escapeHtml(exports.title))
|
||||
.replace('{statusCode}', res.statusCode)
|
||||
.replace(/\{error\}/g, escapeHtml(String(err)).replace(/ /g, ' ').replace(/\n/g, '<br>'));
|
||||
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
||||
res.end(html);
|
||||
});
|
||||
});
|
||||
// json
|
||||
} else if (type === 'json') {
|
||||
var error = { message: err.message, stack: err.stack };
|
||||
for (var prop in err) error[prop] = err[prop];
|
||||
var json = JSON.stringify({ error: error });
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(json);
|
||||
// plain text
|
||||
} else {
|
||||
res.setHeader('Content-Type', 'text/plain');
|
||||
res.end(err.stack || String(err));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Template title, framework authors may override this value.
|
||||
*/
|
||||
|
||||
exports.title = 'Connect';
|
|
@ -0,0 +1,3 @@
|
|||
coverage/
|
||||
test/
|
||||
.travis.yml
|
|
@ -0,0 +1,38 @@
|
|||
|
||||
1.0.6 / 2014-06-24
|
||||
==================
|
||||
|
||||
* deps: negotiator@0.4.7
|
||||
|
||||
1.0.5 / 2014-06-20
|
||||
==================
|
||||
|
||||
* fix crash when unknown extension given
|
||||
|
||||
1.0.4 / 2014-06-19
|
||||
==================
|
||||
|
||||
* use `mime-types`
|
||||
|
||||
1.0.3 / 2014-06-11
|
||||
==================
|
||||
|
||||
* deps: negotiator@0.4.6
|
||||
- Order by specificity when quality is the same
|
||||
|
||||
1.0.2 / 2014-05-29
|
||||
==================
|
||||
|
||||
* Fix interpretation when header not in request
|
||||
* deps: pin negotiator@0.4.5
|
||||
|
||||
1.0.1 / 2014-01-18
|
||||
==================
|
||||
|
||||
* Identity encoding isn't always acceptable
|
||||
* deps: negotiator@~0.4.0
|
||||
|
||||
1.0.0 / 2013-12-27
|
||||
==================
|
||||
|
||||
* Genesis
|
|
@ -0,0 +1,101 @@
|
|||
# Accepts
|
||||
|
||||
[![NPM version](https://badge.fury.io/js/accepts.svg)](http://badge.fury.io/js/accepts)
|
||||
[![Build Status](https://travis-ci.org/expressjs/accepts.svg?branch=master)](https://travis-ci.org/expressjs/accepts)
|
||||
[![Coverage Status](https://img.shields.io/coveralls/expressjs/accepts.svg?branch=master)](https://coveralls.io/r/expressjs/accepts)
|
||||
|
||||
Higher level content negotation based on [negotiator](https://github.com/federomero/negotiator). Extracted from [koa](https://github.com/koajs/koa) for general use.
|
||||
|
||||
In addition to negotatior, it allows:
|
||||
|
||||
- Allows types as an array or arguments list, ie `(['text/html', 'application/json'])` as well as `('text/html', 'application/json')`.
|
||||
- Allows type shorthands such as `json`.
|
||||
- Returns `false` when no types match
|
||||
- Treats non-existent headers as `*`
|
||||
|
||||
## API
|
||||
|
||||
### var accept = new Accepts(req)
|
||||
|
||||
```js
|
||||
var accepts = require('accepts')
|
||||
|
||||
http.createServer(function (req, res) {
|
||||
var accept = accepts(req)
|
||||
})
|
||||
```
|
||||
|
||||
### accept\[property\]\(\)
|
||||
|
||||
Returns all the explicitly accepted content property as an array in descending priority.
|
||||
|
||||
- `accept.types()`
|
||||
- `accept.encodings()`
|
||||
- `accept.charsets()`
|
||||
- `accept.languages()`
|
||||
|
||||
They are also aliased in singular form such as `accept.type()`. `accept.languages()` is also aliased as `accept.langs()`, etc.
|
||||
|
||||
Note: you should almost never do this in a real app as it defeats the purpose of content negotiation.
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
// in Google Chrome
|
||||
var encodings = accept.encodings() // -> ['sdch', 'gzip', 'deflate']
|
||||
```
|
||||
|
||||
Since you probably don't support `sdch`, you should just supply the encodings you support:
|
||||
|
||||
```js
|
||||
var encoding = accept.encodings('gzip', 'deflate') // -> 'gzip', probably
|
||||
```
|
||||
|
||||
### accept\[property\]\(values, ...\)
|
||||
|
||||
You can either have `values` be an array or have an argument list of values.
|
||||
|
||||
If the client does not accept any `values`, `false` will be returned.
|
||||
If the client accepts any `values`, the preferred `value` will be return.
|
||||
|
||||
For `accept.types()`, shorthand mime types are allowed.
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
// req.headers.accept = 'application/json'
|
||||
|
||||
accept.types('json') // -> 'json'
|
||||
accept.types('html', 'json') // -> 'json'
|
||||
accept.types('html') // -> false
|
||||
|
||||
// req.headers.accept = ''
|
||||
// which is equivalent to `*`
|
||||
|
||||
accept.types() // -> [], no explicit types
|
||||
accept.types('text/html', 'text/json') // -> 'text/html', since it was first
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 Jonathan Ong me@jongleberry.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
|
@ -0,0 +1,160 @@
|
|||
var Negotiator = require('negotiator')
|
||||
var mime = require('mime-types')
|
||||
|
||||
var slice = [].slice
|
||||
|
||||
module.exports = Accepts
|
||||
|
||||
function Accepts(req) {
|
||||
if (!(this instanceof Accepts))
|
||||
return new Accepts(req)
|
||||
|
||||
this.headers = req.headers
|
||||
this.negotiator = Negotiator(req)
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given `type(s)` is acceptable, returning
|
||||
* the best match when true, otherwise `undefined`, in which
|
||||
* case you should respond with 406 "Not Acceptable".
|
||||
*
|
||||
* The `type` value may be a single mime type string
|
||||
* such as "application/json", the extension name
|
||||
* such as "json" or an array `["json", "html", "text/plain"]`. When a list
|
||||
* or array is given the _best_ match, if any is returned.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* // Accept: text/html
|
||||
* this.types('html');
|
||||
* // => "html"
|
||||
*
|
||||
* // Accept: text/*, application/json
|
||||
* this.types('html');
|
||||
* // => "html"
|
||||
* this.types('text/html');
|
||||
* // => "text/html"
|
||||
* this.types('json', 'text');
|
||||
* // => "json"
|
||||
* this.types('application/json');
|
||||
* // => "application/json"
|
||||
*
|
||||
* // Accept: text/*, application/json
|
||||
* this.types('image/png');
|
||||
* this.types('png');
|
||||
* // => undefined
|
||||
*
|
||||
* // Accept: text/*;q=.5, application/json
|
||||
* this.types(['html', 'json']);
|
||||
* this.types('html', 'json');
|
||||
* // => "json"
|
||||
*
|
||||
* @param {String|Array} type(s)...
|
||||
* @return {String|Array|Boolean}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Accepts.prototype.type =
|
||||
Accepts.prototype.types = function (types) {
|
||||
if (!Array.isArray(types)) types = slice.call(arguments);
|
||||
var n = this.negotiator;
|
||||
if (!types.length) return n.mediaTypes();
|
||||
if (!this.headers.accept) return types[0];
|
||||
var mimes = types.map(extToMime).filter(validMime);
|
||||
var accepts = n.mediaTypes(mimes);
|
||||
var first = accepts[0];
|
||||
if (!first) return false;
|
||||
return types[mimes.indexOf(first)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return accepted encodings or best fit based on `encodings`.
|
||||
*
|
||||
* Given `Accept-Encoding: gzip, deflate`
|
||||
* an array sorted by quality is returned:
|
||||
*
|
||||
* ['gzip', 'deflate']
|
||||
*
|
||||
* @param {String|Array} encoding(s)...
|
||||
* @return {String|Array}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Accepts.prototype.encoding =
|
||||
Accepts.prototype.encodings = function (encodings) {
|
||||
if (!Array.isArray(encodings)) encodings = slice.call(arguments);
|
||||
var n = this.negotiator;
|
||||
if (!encodings.length) return n.encodings();
|
||||
return n.encodings(encodings)[0] || false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return accepted charsets or best fit based on `charsets`.
|
||||
*
|
||||
* Given `Accept-Charset: utf-8, iso-8859-1;q=0.2, utf-7;q=0.5`
|
||||
* an array sorted by quality is returned:
|
||||
*
|
||||
* ['utf-8', 'utf-7', 'iso-8859-1']
|
||||
*
|
||||
* @param {String|Array} charset(s)...
|
||||
* @return {String|Array}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Accepts.prototype.charset =
|
||||
Accepts.prototype.charsets = function (charsets) {
|
||||
if (!Array.isArray(charsets)) charsets = [].slice.call(arguments);
|
||||
var n = this.negotiator;
|
||||
if (!charsets.length) return n.charsets();
|
||||
if (!this.headers['accept-charset']) return charsets[0];
|
||||
return n.charsets(charsets)[0] || false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return accepted languages or best fit based on `langs`.
|
||||
*
|
||||
* Given `Accept-Language: en;q=0.8, es, pt`
|
||||
* an array sorted by quality is returned:
|
||||
*
|
||||
* ['es', 'pt', 'en']
|
||||
*
|
||||
* @param {String|Array} lang(s)...
|
||||
* @return {Array|String}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Accepts.prototype.lang =
|
||||
Accepts.prototype.langs =
|
||||
Accepts.prototype.language =
|
||||
Accepts.prototype.languages = function (langs) {
|
||||
if (!Array.isArray(langs)) langs = slice.call(arguments);
|
||||
var n = this.negotiator;
|
||||
if (!langs.length) return n.languages();
|
||||
if (!this.headers['accept-language']) return langs[0];
|
||||
return n.languages(langs)[0] || false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert extnames to mime.
|
||||
*
|
||||
* @param {String} type
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function extToMime(type) {
|
||||
if (~type.indexOf('/')) return type;
|
||||
return mime.lookup(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if mime is valid.
|
||||
*
|
||||
* @param {String} type
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function validMime(type) {
|
||||
return typeof type === 'string';
|
||||
}
|
14
node_modules/errorhandler/node_modules/accepts/node_modules/mime-types/.npmignore
generated
vendored
100755
14
node_modules/errorhandler/node_modules/accepts/node_modules/mime-types/.npmignore
generated
vendored
100755
|
@ -0,0 +1,14 @@
|
|||
test
|
||||
build.js
|
||||
|
||||
# OS generated files #
|
||||
######################
|
||||
.DS_Store*
|
||||
# Icon?
|
||||
ehthumbs.db
|
||||
Thumbs.db
|
||||
|
||||
# Node.js #
|
||||
###########
|
||||
node_modules
|
||||
npm-debug.log
|
12
node_modules/errorhandler/node_modules/accepts/node_modules/mime-types/.travis.yml
generated
vendored
100755
12
node_modules/errorhandler/node_modules/accepts/node_modules/mime-types/.travis.yml
generated
vendored
100755
|
@ -0,0 +1,12 @@
|
|||
language: node_js
|
||||
node_js:
|
||||
- "0.8"
|
||||
- "0.10"
|
||||
- "0.11"
|
||||
matrix:
|
||||
allow_failures:
|
||||
- node_js: "0.11"
|
||||
fast_finish: true
|
||||
before_install:
|
||||
# remove build script deps before install
|
||||
- node -pe 'f="./package.json";p=require(f);d=p.devDependencies;for(k in d){if("co"===k.substr(0,2))delete d[k]}require("fs").writeFileSync(f,JSON.stringify(p,null,2))'
|
22
node_modules/errorhandler/node_modules/accepts/node_modules/mime-types/LICENSE
generated
vendored
100755
22
node_modules/errorhandler/node_modules/accepts/node_modules/mime-types/LICENSE
generated
vendored
100755
|
@ -0,0 +1,22 @@
|
|||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Jonathan Ong me@jongleberry.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
9
node_modules/errorhandler/node_modules/accepts/node_modules/mime-types/Makefile
generated
vendored
100755
9
node_modules/errorhandler/node_modules/accepts/node_modules/mime-types/Makefile
generated
vendored
100755
|
@ -0,0 +1,9 @@
|
|||
|
||||
build:
|
||||
node --harmony-generators build.js
|
||||
|
||||
test:
|
||||
node test/mime.js
|
||||
mocha --require should --reporter spec test/test.js
|
||||
|
||||
.PHONY: build test
|
101
node_modules/errorhandler/node_modules/accepts/node_modules/mime-types/README.md
generated
vendored
100755
101
node_modules/errorhandler/node_modules/accepts/node_modules/mime-types/README.md
generated
vendored
100755
|
@ -0,0 +1,101 @@
|
|||
# mime-types
|
||||
[![NPM version](https://badge.fury.io/js/mime-types.svg)](https://badge.fury.io/js/mime-types) [![Build Status](https://travis-ci.org/expressjs/mime-types.svg?branch=master)](https://travis-ci.org/expressjs/mime-types)
|
||||
|
||||
The ultimate javascript content-type utility.
|
||||
|
||||
### Install
|
||||
|
||||
```sh
|
||||
$ npm install mime-types
|
||||
```
|
||||
|
||||
#### Similar to [node-mime](https://github.com/broofa/node-mime), except:
|
||||
|
||||
- __No fallbacks.__ Instead of naively returning the first available type, `mime-types` simply returns `false`, so do `var type = mime.lookup('unrecognized') || 'application/octet-stream'`.
|
||||
- No `new Mime()` business, so you could do `var lookup = require('mime-types').lookup`.
|
||||
- Additional mime types are added such as jade and stylus. Feel free to add more!
|
||||
- Browser support via Browserify and Component by converting lists to JSON files.
|
||||
|
||||
Otherwise, the API is compatible.
|
||||
|
||||
### Adding Types
|
||||
|
||||
If you'd like to add additional types,
|
||||
simply create a PR adding the type to `custom.json` and
|
||||
a reference link to the [sources](SOURCES.md).
|
||||
|
||||
Do __NOT__ edit `mime.json` or `node.json`.
|
||||
Those are pulled using `build.js`.
|
||||
You should only touch `custom.json`.
|
||||
|
||||
## API
|
||||
|
||||
```js
|
||||
var mime = require('mime-types')
|
||||
```
|
||||
|
||||
All functions return `false` if input is invalid or not found.
|
||||
|
||||
### mime.lookup(path)
|
||||
|
||||
Lookup the content-type associated with a file.
|
||||
|
||||
```js
|
||||
mime.lookup('json') // 'application/json'
|
||||
mime.lookup('.md') // 'text/x-markdown'
|
||||
mime.lookup('file.html') // 'text/html'
|
||||
mime.lookup('folder/file.js') // 'application/javascript'
|
||||
|
||||
mime.lookup('cats') // false
|
||||
```
|
||||
|
||||
### mime.contentType(type)
|
||||
|
||||
Create a full content-type header given a content-type or extension.
|
||||
|
||||
```js
|
||||
mime.contentType('markdown') // 'text/x-markdown; charset=utf-8'
|
||||
mime.contentType('file.json') // 'application/json; charset=utf-8'
|
||||
```
|
||||
|
||||
### mime.extension(type)
|
||||
|
||||
Get the default extension for a content-type.
|
||||
|
||||
```js
|
||||
mime.extension('application/octet-stream') // 'bin'
|
||||
```
|
||||
|
||||
### mime.charset(type)
|
||||
|
||||
Lookup the implied default charset of a content-type.
|
||||
|
||||
```js
|
||||
mime.charset('text/x-markdown') // 'UTF-8'
|
||||
```
|
||||
|
||||
### mime.types[extension] = type
|
||||
|
||||
A map of content-types by extension.
|
||||
|
||||
### mime.extensions[type] = [extensions]
|
||||
|
||||
A map of extensions by content-type.
|
||||
|
||||
### mime.define(types)
|
||||
|
||||
Globally add definitions.
|
||||
`types` must be an object of the form:
|
||||
|
||||
```js
|
||||
{
|
||||
"<content-type>": [extensions...],
|
||||
"<content-type>": [extensions...]
|
||||
}
|
||||
```
|
||||
|
||||
See the `.json` files in `lib/` for examples.
|
||||
|
||||
## License
|
||||
|
||||
[MIT](LICENSE)
|
17
node_modules/errorhandler/node_modules/accepts/node_modules/mime-types/SOURCES.md
generated
vendored
100755
17
node_modules/errorhandler/node_modules/accepts/node_modules/mime-types/SOURCES.md
generated
vendored
100755
|
@ -0,0 +1,17 @@
|
|||
|
||||
### Sources for custom types
|
||||
|
||||
This is a list of sources for any custom mime types.
|
||||
When adding custom mime types, please link to where you found the mime type,
|
||||
even if it's from an unofficial source.
|
||||
|
||||
- `text/coffeescript` - http://coffeescript.org/#scripts
|
||||
- `text/x-handlebars-template` - https://handlebarsjs.com/#getting-started
|
||||
- `text/x-sass` & `text/x-scss` - https://github.com/janlelis/rubybuntu-mime/blob/master/sass.xml
|
||||
- `text.jsx` - http://facebook.github.io/react/docs/getting-started.html [[2]](https://github.com/facebook/react/blob/f230e0a03154e6f8a616e0da1fb3d97ffa1a6472/vendor/browser-transforms.js#L210)
|
||||
|
||||
[Sources for node.json types](https://github.com/broofa/node-mime/blob/master/types/node.types)
|
||||
|
||||
### Notes on weird types
|
||||
|
||||
- `font/opentype` - This type is technically invalid according to the spec. No valid types begin with `font/`. No-one uses the official type of `application/vnd.ms-opentype` as the community standardized `application/x-font-otf`. However, chrome logs nonsense warnings unless opentype fonts are served with `font/opentype`. [[1]](http://stackoverflow.com/questions/2871655/proper-mime-type-for-fonts)
|
16
node_modules/errorhandler/node_modules/accepts/node_modules/mime-types/component.json
generated
vendored
100755
16
node_modules/errorhandler/node_modules/accepts/node_modules/mime-types/component.json
generated
vendored
100755
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"name": "mime-types",
|
||||
"description": "The ultimate javascript content-type utility.",
|
||||
"version": "0.1.0",
|
||||
"author": {
|
||||
"name": "Jonathan Ong",
|
||||
"email": "me@jongleberry.com",
|
||||
"url": "http://jongleberry.com",
|
||||
"twitter": "https://twitter.com/jongleberry"
|
||||
},
|
||||
"repository": "expressjs/mime-types",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"scripts": ["lib/index.js"],
|
||||
"json": ["mime.json", "node.json", "custom.json"]
|
||||
}
|
27
node_modules/errorhandler/node_modules/accepts/node_modules/mime-types/lib/custom.json
generated
vendored
100755
27
node_modules/errorhandler/node_modules/accepts/node_modules/mime-types/lib/custom.json
generated
vendored
100755
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"text/jade": [
|
||||
"jade"
|
||||
],
|
||||
"text/stylus": [
|
||||
"stylus",
|
||||
"styl"
|
||||
],
|
||||
"text/less": [
|
||||
"less"
|
||||
],
|
||||
"text/x-sass": [
|
||||
"sass"
|
||||
],
|
||||
"text/x-scss": [
|
||||
"scss"
|
||||
],
|
||||
"text/coffeescript": [
|
||||
"coffee"
|
||||
],
|
||||
"text/x-handlebars-template": [
|
||||
"hbs"
|
||||
],
|
||||
"text/jsx": [
|
||||
"jsx"
|
||||
]
|
||||
}
|
74
node_modules/errorhandler/node_modules/accepts/node_modules/mime-types/lib/index.js
generated
vendored
100755
74
node_modules/errorhandler/node_modules/accepts/node_modules/mime-types/lib/index.js
generated
vendored
100755
|
@ -0,0 +1,74 @@
|
|||
|
||||
// types[extension] = type
|
||||
exports.types = Object.create(null)
|
||||
// extensions[type] = [extensions]
|
||||
exports.extensions = Object.create(null)
|
||||
// define more mime types
|
||||
exports.define = define
|
||||
|
||||
// store the json files
|
||||
exports.json = {
|
||||
mime: require('./mime.json'),
|
||||
node: require('./node.json'),
|
||||
custom: require('./custom.json'),
|
||||
}
|
||||
|
||||
exports.lookup = function (string) {
|
||||
if (!string || typeof string !== "string") return false
|
||||
string = string.replace(/.*[\.\/\\]/, '').toLowerCase()
|
||||
if (!string) return false
|
||||
return exports.types[string] || false
|
||||
}
|
||||
|
||||
exports.extension = function (type) {
|
||||
if (!type || typeof type !== "string") return false
|
||||
type = type.match(/^\s*([^;\s]*)(?:;|\s|$)/)
|
||||
if (!type) return false
|
||||
var exts = exports.extensions[type[1].toLowerCase()]
|
||||
if (!exts || !exts.length) return false
|
||||
return exts[0]
|
||||
}
|
||||
|
||||
// type has to be an exact mime type
|
||||
exports.charset = function (type) {
|
||||
// special cases
|
||||
switch (type) {
|
||||
case 'application/json': return 'UTF-8'
|
||||
}
|
||||
|
||||
// default text/* to utf-8
|
||||
if (/^text\//.test(type)) return 'UTF-8'
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// backwards compatibility
|
||||
exports.charsets = {
|
||||
lookup: exports.charset
|
||||
}
|
||||
|
||||
exports.contentType = function (type) {
|
||||
if (!type || typeof type !== "string") return false
|
||||
if (!~type.indexOf('/')) type = exports.lookup(type)
|
||||
if (!type) return false
|
||||
if (!~type.indexOf('charset')) {
|
||||
var charset = exports.charset(type)
|
||||
if (charset) type += '; charset=' + charset.toLowerCase()
|
||||
}
|
||||
return type
|
||||
}
|
||||
|
||||
define(exports.json.mime)
|
||||
define(exports.json.node)
|
||||
define(exports.json.custom)
|
||||
|
||||
function define(json) {
|
||||
Object.keys(json).forEach(function (type) {
|
||||
var exts = json[type] || []
|
||||
exports.extensions[type] = exports.extensions[type] || []
|
||||
exts.forEach(function (ext) {
|
||||
if (!~exports.extensions[type].indexOf(ext)) exports.extensions[type].push(ext)
|
||||
exports.types[ext] = type
|
||||
})
|
||||
})
|
||||
}
|
3317
node_modules/errorhandler/node_modules/accepts/node_modules/mime-types/lib/mime.json
generated
vendored
100755
3317
node_modules/errorhandler/node_modules/accepts/node_modules/mime-types/lib/mime.json
generated
vendored
100755
File diff suppressed because it is too large
Load Diff
55
node_modules/errorhandler/node_modules/accepts/node_modules/mime-types/lib/node.json
generated
vendored
100755
55
node_modules/errorhandler/node_modules/accepts/node_modules/mime-types/lib/node.json
generated
vendored
100755
|
@ -0,0 +1,55 @@
|
|||
{
|
||||
"text/vtt": [
|
||||
"vtt"
|
||||
],
|
||||
"application/x-chrome-extension": [
|
||||
"crx"
|
||||
],
|
||||
"text/x-component": [
|
||||
"htc"
|
||||
],
|
||||
"text/cache-manifest": [
|
||||
"manifest"
|
||||
],
|
||||
"application/octet-stream": [
|
||||
"buffer"
|
||||
],
|
||||
"application/mp4": [
|
||||
"m4p"
|
||||
],
|
||||
"audio/mp4": [
|
||||
"m4a"
|
||||
],
|
||||
"video/MP2T": [
|
||||
"ts"
|
||||
],
|
||||
"application/x-web-app-manifest+json": [
|
||||
"webapp"
|
||||
],
|
||||
"text/x-lua": [
|
||||
"lua"
|
||||
],
|
||||
"application/x-lua-bytecode": [
|
||||
"luac"
|
||||
],
|
||||
"text/x-markdown": [
|
||||
"markdown",
|
||||
"md",
|
||||
"mkd"
|
||||
],
|
||||
"text/plain": [
|
||||
"ini"
|
||||
],
|
||||
"application/dash+xml": [
|
||||
"mdp"
|
||||
],
|
||||
"font/opentype": [
|
||||
"otf"
|
||||
],
|
||||
"application/json": [
|
||||
"map"
|
||||
],
|
||||
"application/xml": [
|
||||
"xsd"
|
||||
]
|
||||
}
|
42
node_modules/errorhandler/node_modules/accepts/node_modules/mime-types/package.json
generated
vendored
100755
42
node_modules/errorhandler/node_modules/accepts/node_modules/mime-types/package.json
generated
vendored
100755
|
@ -0,0 +1,42 @@
|
|||
{
|
||||
"name": "mime-types",
|
||||
"description": "The ultimate javascript content-type utility.",
|
||||
"version": "1.0.1",
|
||||
"author": {
|
||||
"name": "Jonathan Ong",
|
||||
"email": "me@jongleberry.com",
|
||||
"url": "http://jongleberry.com"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Jeremiah Senkpiel",
|
||||
"email": "fishrock123@rocketmail.com",
|
||||
"url": "https://searchbeam.jit.su"
|
||||
}
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/expressjs/mime-types"
|
||||
},
|
||||
"license": "MIT",
|
||||
"main": "lib",
|
||||
"devDependencies": {
|
||||
"co": "3",
|
||||
"cogent": "0",
|
||||
"mocha": "1",
|
||||
"should": "3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "make test"
|
||||
},
|
||||
"readme": "# mime-types\n[![NPM version](https://badge.fury.io/js/mime-types.svg)](https://badge.fury.io/js/mime-types) [![Build Status](https://travis-ci.org/expressjs/mime-types.svg?branch=master)](https://travis-ci.org/expressjs/mime-types)\n\nThe ultimate javascript content-type utility.\n\n### Install\n\n```sh\n$ npm install mime-types\n```\n\n#### Similar to [node-mime](https://github.com/broofa/node-mime), except:\n\n- __No fallbacks.__ Instead of naively returning the first available type, `mime-types` simply returns `false`, so do `var type = mime.lookup('unrecognized') || 'application/octet-stream'`.\n- No `new Mime()` business, so you could do `var lookup = require('mime-types').lookup`.\n- Additional mime types are added such as jade and stylus. Feel free to add more!\n- Browser support via Browserify and Component by converting lists to JSON files.\n\nOtherwise, the API is compatible.\n\n### Adding Types\n\nIf you'd like to add additional types,\nsimply create a PR adding the type to `custom.json` and\na reference link to the [sources](SOURCES.md).\n\nDo __NOT__ edit `mime.json` or `node.json`.\nThose are pulled using `build.js`.\nYou should only touch `custom.json`.\n\n## API\n\n```js\nvar mime = require('mime-types')\n```\n\nAll functions return `false` if input is invalid or not found.\n\n### mime.lookup(path)\n\nLookup the content-type associated with a file.\n\n```js\nmime.lookup('json') // 'application/json'\nmime.lookup('.md') // 'text/x-markdown'\nmime.lookup('file.html') // 'text/html'\nmime.lookup('folder/file.js') // 'application/javascript'\n\nmime.lookup('cats') // false\n```\n\n### mime.contentType(type)\n\nCreate a full content-type header given a content-type or extension.\n\n```js\nmime.contentType('markdown') // 'text/x-markdown; charset=utf-8'\nmime.contentType('file.json') // 'application/json; charset=utf-8'\n```\n\n### mime.extension(type)\n\nGet the default extension for a content-type.\n\n```js\nmime.extension('application/octet-stream') // 'bin'\n```\n\n### mime.charset(type)\n\nLookup the implied default charset of a content-type.\n\n```js\nmime.charset('text/x-markdown') // 'UTF-8'\n```\n\n### mime.types[extension] = type\n\nA map of content-types by extension.\n\n### mime.extensions[type] = [extensions]\n\nA map of extensions by content-type.\n\n### mime.define(types)\n\nGlobally add definitions.\n`types` must be an object of the form:\n\n```js\n{\n \"<content-type>\": [extensions...],\n \"<content-type>\": [extensions...]\n}\n```\n\nSee the `.json` files in `lib/` for examples.\n\n## License\n\n[MIT](LICENSE)\n",
|
||||
"readmeFilename": "README.md",
|
||||
"bugs": {
|
||||
"url": "https://github.com/expressjs/mime-types/issues"
|
||||
},
|
||||
"_id": "mime-types@1.0.1",
|
||||
"_from": "mime-types@~1.0.0"
|
||||
}
|
3
node_modules/errorhandler/node_modules/accepts/node_modules/negotiator/.npmignore
generated
vendored
100755
3
node_modules/errorhandler/node_modules/accepts/node_modules/negotiator/.npmignore
generated
vendored
100755
|
@ -0,0 +1,3 @@
|
|||
examples
|
||||
test
|
||||
.travis.yml
|
27
node_modules/errorhandler/node_modules/accepts/node_modules/negotiator/LICENSE
generated
vendored
100755
27
node_modules/errorhandler/node_modules/accepts/node_modules/negotiator/LICENSE
generated
vendored
100755
|
@ -0,0 +1,27 @@
|
|||
Original "Negotiator" program Copyright Federico Romero
|
||||
Port to JavaScript Copyright Isaac Z. Schlueter
|
||||
|
||||
All rights reserved.
|
||||
|
||||
MIT License
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
90
node_modules/errorhandler/node_modules/accepts/node_modules/negotiator/lib/charset.js
generated
vendored
100755
90
node_modules/errorhandler/node_modules/accepts/node_modules/negotiator/lib/charset.js
generated
vendored
100755
|
@ -0,0 +1,90 @@
|
|||
module.exports = preferredCharsets;
|
||||
preferredCharsets.preferredCharsets = preferredCharsets;
|
||||
|
||||
function parseAcceptCharset(accept) {
|
||||
return accept.split(',').map(function(e) {
|
||||
return parseCharset(e.trim());
|
||||
}).filter(function(e) {
|
||||
return e;
|
||||
});
|
||||
}
|
||||
|
||||
function parseCharset(s) {
|
||||
var match = s.match(/^\s*(\S+?)\s*(?:;(.*))?$/);
|
||||
if (!match) return null;
|
||||
|
||||
var charset = match[1];
|
||||
var q = 1;
|
||||
if (match[2]) {
|
||||
var params = match[2].split(';')
|
||||
for (var i = 0; i < params.length; i ++) {
|
||||
var p = params[i].trim().split('=');
|
||||
if (p[0] === 'q') {
|
||||
q = parseFloat(p[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
charset: charset,
|
||||
q: q
|
||||
};
|
||||
}
|
||||
|
||||
function getCharsetPriority(charset, accepted) {
|
||||
return (accepted.map(function(a) {
|
||||
return specify(charset, a);
|
||||
}).filter(Boolean).sort(function (a, b) {
|
||||
if(a.s == b.s) {
|
||||
return a.q > b.q ? -1 : 1;
|
||||
} else {
|
||||
return a.s > b.s ? -1 : 1;
|
||||
}
|
||||
})[0] || {s: 0, q:0});
|
||||
}
|
||||
|
||||
function specify(charset, spec) {
|
||||
var s = 0;
|
||||
if(spec.charset === charset){
|
||||
s |= 1;
|
||||
} else if (spec.charset !== '*' ) {
|
||||
return null
|
||||
}
|
||||
|
||||
return {
|
||||
s: s,
|
||||
q: spec.q,
|
||||
}
|
||||
}
|
||||
|
||||
function preferredCharsets(accept, provided) {
|
||||
// RFC 2616 sec 14.2: no header = *
|
||||
accept = parseAcceptCharset(accept === undefined ? '*' : accept || '');
|
||||
if (provided) {
|
||||
return provided.map(function(type) {
|
||||
return [type, getCharsetPriority(type, accept)];
|
||||
}).filter(function(pair) {
|
||||
return pair[1].q > 0;
|
||||
}).sort(function(a, b) {
|
||||
var pa = a[1];
|
||||
var pb = b[1];
|
||||
if(pa.q == pb.q) {
|
||||
return pa.s < pb.s ? 1 : -1;
|
||||
} else {
|
||||
return pa.q < pb.q ? 1 : -1;
|
||||
}
|
||||
}).map(function(pair) {
|
||||
return pair[0];
|
||||
});
|
||||
} else {
|
||||
return accept.sort(function (a, b) {
|
||||
// revsort
|
||||
return a.q < b.q ? 1 : -1;
|
||||
}).filter(function(type) {
|
||||
return type.q > 0;
|
||||
}).map(function(type) {
|
||||
return type.charset;
|
||||
});
|
||||
}
|
||||
}
|
120
node_modules/errorhandler/node_modules/accepts/node_modules/negotiator/lib/encoding.js
generated
vendored
100755
120
node_modules/errorhandler/node_modules/accepts/node_modules/negotiator/lib/encoding.js
generated
vendored
100755
|
@ -0,0 +1,120 @@
|
|||
module.exports = preferredEncodings;
|
||||
preferredEncodings.preferredEncodings = preferredEncodings;
|
||||
|
||||
function parseAcceptEncoding(accept) {
|
||||
var acceptableEncodings;
|
||||
|
||||
if (accept) {
|
||||
acceptableEncodings = accept.split(',').map(function(e) {
|
||||
return parseEncoding(e.trim());
|
||||
});
|
||||
} else {
|
||||
acceptableEncodings = [];
|
||||
}
|
||||
|
||||
if (!acceptableEncodings.some(function(e) {
|
||||
return e && specify('identity', e);
|
||||
})) {
|
||||
/*
|
||||
* If identity doesn't explicitly appear in the accept-encoding header,
|
||||
* it's added to the list of acceptable encoding with the lowest q
|
||||
*
|
||||
*/
|
||||
var lowestQ = 1;
|
||||
|
||||
for(var i = 0; i < acceptableEncodings.length; i++){
|
||||
var e = acceptableEncodings[i];
|
||||
if(e && e.q < lowestQ){
|
||||
lowestQ = e.q;
|
||||
}
|
||||
}
|
||||
acceptableEncodings.push({
|
||||
encoding: 'identity',
|
||||
q: lowestQ / 2,
|
||||
});
|
||||
}
|
||||
|
||||
return acceptableEncodings.filter(function(e) {
|
||||
return e;
|
||||
});
|
||||
}
|
||||
|
||||
function parseEncoding(s) {
|
||||
var match = s.match(/^\s*(\S+?)\s*(?:;(.*))?$/);
|
||||
|
||||
if (!match) return null;
|
||||
|
||||
var encoding = match[1];
|
||||
var q = 1;
|
||||
if (match[2]) {
|
||||
var params = match[2].split(';');
|
||||
for (var i = 0; i < params.length; i ++) {
|
||||
var p = params[i].trim().split('=');
|
||||
if (p[0] === 'q') {
|
||||
q = parseFloat(p[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
encoding: encoding,
|
||||
q: q
|
||||
};
|
||||
}
|
||||
|
||||
function getEncodingPriority(encoding, accepted) {
|
||||
return (accepted.map(function(a) {
|
||||
return specify(encoding, a);
|
||||
}).filter(Boolean).sort(function (a, b) {
|
||||
if(a.s == b.s) {
|
||||
return a.q > b.q ? -1 : 1;
|
||||
} else {
|
||||
return a.s > b.s ? -1 : 1;
|
||||
}
|
||||
})[0] || {s: 0, q: 0});
|
||||
}
|
||||
|
||||
function specify(encoding, spec) {
|
||||
var s = 0;
|
||||
if(spec.encoding === encoding){
|
||||
s |= 1;
|
||||
} else if (spec.encoding !== '*' ) {
|
||||
return null
|
||||
}
|
||||
|
||||
return {
|
||||
s: s,
|
||||
q: spec.q,
|
||||
}
|
||||
};
|
||||
|
||||
function preferredEncodings(accept, provided) {
|
||||
accept = parseAcceptEncoding(accept || '');
|
||||
if (provided) {
|
||||
return provided.map(function(type) {
|
||||
return [type, getEncodingPriority(type, accept)];
|
||||
}).filter(function(pair) {
|
||||
return pair[1].q > 0;
|
||||
}).sort(function(a, b) {
|
||||
var pa = a[1];
|
||||
var pb = b[1];
|
||||
if(pa.q == pb.q) {
|
||||
return pa.s < pb.s ? 1 : -1;
|
||||
} else {
|
||||
return pa.q < pb.q ? 1 : -1;
|
||||
}
|
||||
}).map(function(pair) {
|
||||
return pair[0];
|
||||
});
|
||||
} else {
|
||||
return accept.sort(function (a, b) {
|
||||
// revsort
|
||||
return a.q < b.q ? 1 : -1;
|
||||
}).filter(function(type){
|
||||
return type.q > 0;
|
||||
}).map(function(type) {
|
||||
return type.encoding;
|
||||
});
|
||||
}
|
||||
}
|
103
node_modules/errorhandler/node_modules/accepts/node_modules/negotiator/lib/language.js
generated
vendored
100755
103
node_modules/errorhandler/node_modules/accepts/node_modules/negotiator/lib/language.js
generated
vendored
100755
|
@ -0,0 +1,103 @@
|
|||
module.exports = preferredLanguages;
|
||||
preferredLanguages.preferredLanguages = preferredLanguages;
|
||||
|
||||
function parseAcceptLanguage(accept) {
|
||||
return accept.split(',').map(function(e) {
|
||||
return parseLanguage(e.trim());
|
||||
}).filter(function(e) {
|
||||
return e;
|
||||
});
|
||||
}
|
||||
|
||||
function parseLanguage(s) {
|
||||
var match = s.match(/^\s*(\S+?)(?:-(\S+?))?\s*(?:;(.*))?$/);
|
||||
if (!match) return null;
|
||||
|
||||
var prefix = match[1],
|
||||
suffix = match[2],
|
||||
full = prefix;
|
||||
|
||||
if (suffix) full += "-" + suffix;
|
||||
|
||||
var q = 1;
|
||||
if (match[3]) {
|
||||
var params = match[3].split(';')
|
||||
for (var i = 0; i < params.length; i ++) {
|
||||
var p = params[i].split('=');
|
||||
if (p[0] === 'q') q = parseFloat(p[1]);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
prefix: prefix,
|
||||
suffix: suffix,
|
||||
q: q,
|
||||
full: full
|
||||
};
|
||||
}
|
||||
|
||||
function getLanguagePriority(language, accepted) {
|
||||
return (accepted.map(function(a){
|
||||
return specify(language, a);
|
||||
}).filter(Boolean).sort(function (a, b) {
|
||||
if(a.s == b.s) {
|
||||
return a.q > b.q ? -1 : 1;
|
||||
} else {
|
||||
return a.s > b.s ? -1 : 1;
|
||||
}
|
||||
})[0] || {s: 0, q: 0});
|
||||
}
|
||||
|
||||
function specify(language, spec) {
|
||||
var p = parseLanguage(language)
|
||||
if (!p) return null;
|
||||
var s = 0;
|
||||
if(spec.full === p.full){
|
||||
s |= 4;
|
||||
} else if (spec.prefix === p.full) {
|
||||
s |= 2;
|
||||
} else if (spec.full === p.prefix) {
|
||||
s |= 1;
|
||||
} else if (spec.full !== '*' ) {
|
||||
return null
|
||||
}
|
||||
|
||||
return {
|
||||
s: s,
|
||||
q: spec.q,
|
||||
}
|
||||
};
|
||||
|
||||
function preferredLanguages(accept, provided) {
|
||||
// RFC 2616 sec 14.4: no header = *
|
||||
accept = parseAcceptLanguage(accept === undefined ? '*' : accept || '');
|
||||
if (provided) {
|
||||
|
||||
var ret = provided.map(function(type) {
|
||||
return [type, getLanguagePriority(type, accept)];
|
||||
}).filter(function(pair) {
|
||||
return pair[1].q > 0;
|
||||
}).sort(function(a, b) {
|
||||
var pa = a[1];
|
||||
var pb = b[1];
|
||||
if(pa.q == pb.q) {
|
||||
return pa.s < pb.s ? 1 : -1;
|
||||
} else {
|
||||
return pa.q < pb.q ? 1 : -1;
|
||||
}
|
||||
}).map(function(pair) {
|
||||
return pair[0];
|
||||
});
|
||||
return ret;
|
||||
|
||||
} else {
|
||||
return accept.sort(function (a, b) {
|
||||
// revsort
|
||||
return a.q < b.q ? 1 : -1;
|
||||
}).filter(function(type) {
|
||||
return type.q > 0;
|
||||
}).map(function(type) {
|
||||
return type.full;
|
||||
});
|
||||
}
|
||||
}
|
125
node_modules/errorhandler/node_modules/accepts/node_modules/negotiator/lib/mediaType.js
generated
vendored
100755
125
node_modules/errorhandler/node_modules/accepts/node_modules/negotiator/lib/mediaType.js
generated
vendored
100755
|
@ -0,0 +1,125 @@
|
|||
module.exports = preferredMediaTypes;
|
||||
preferredMediaTypes.preferredMediaTypes = preferredMediaTypes;
|
||||
|
||||
function parseAccept(accept) {
|
||||
return accept.split(',').map(function(e) {
|
||||
return parseMediaType(e.trim());
|
||||
}).filter(function(e) {
|
||||
return e;
|
||||
});
|
||||
};
|
||||
|
||||
function parseMediaType(s) {
|
||||
var match = s.match(/\s*(\S+?)\/([^;\s]+)\s*(?:;(.*))?/);
|
||||
if (!match) return null;
|
||||
|
||||
var type = match[1],
|
||||
subtype = match[2],
|
||||
full = "" + type + "/" + subtype,
|
||||
params = {},
|
||||
q = 1;
|
||||
|
||||
if (match[3]) {
|
||||
params = match[3].split(';').map(function(s) {
|
||||
return s.trim().split('=');
|
||||
}).reduce(function (set, p) {
|
||||
set[p[0]] = p[1];
|
||||
return set
|
||||
}, params);
|
||||
|
||||
if (params.q != null) {
|
||||
q = parseFloat(params.q);
|
||||
delete params.q;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
type: type,
|
||||
subtype: subtype,
|
||||
params: params,
|
||||
q: q,
|
||||
full: full
|
||||
};
|
||||
}
|
||||
|
||||
function getMediaTypePriority(type, accepted) {
|
||||
return (accepted.map(function(a) {
|
||||
return specify(type, a);
|
||||
}).filter(Boolean).sort(function (a, b) {
|
||||
if(a.s == b.s) {
|
||||
return a.q > b.q ? -1 : 1;
|
||||
} else {
|
||||
return a.s > b.s ? -1 : 1;
|
||||
}
|
||||
})[0] || {s: 0, q: 0});
|
||||
}
|
||||
|
||||
function specify(type, spec) {
|
||||
var p = parseMediaType(type);
|
||||
var s = 0;
|
||||
|
||||
if (!p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(spec.type == p.type) {
|
||||
s |= 4
|
||||
} else if(spec.type != '*') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(spec.subtype == p.subtype) {
|
||||
s |= 2
|
||||
} else if(spec.subtype != '*') {
|
||||
return null;
|
||||
}
|
||||
|
||||
var keys = Object.keys(spec.params);
|
||||
if (keys.length > 0) {
|
||||
if (keys.every(function (k) {
|
||||
return spec.params[k] == '*' || spec.params[k] == p.params[k];
|
||||
})) {
|
||||
s |= 1
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
q: spec.q,
|
||||
s: s,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function preferredMediaTypes(accept, provided) {
|
||||
// RFC 2616 sec 14.2: no header = */*
|
||||
accept = parseAccept(accept === undefined ? '*/*' : accept || '');
|
||||
if (provided) {
|
||||
return provided.map(function(type) {
|
||||
return [type, getMediaTypePriority(type, accept)];
|
||||
}).filter(function(pair) {
|
||||
return pair[1].q > 0;
|
||||
}).sort(function(a, b) {
|
||||
var pa = a[1];
|
||||
var pb = b[1];
|
||||
if(pa.q == pb.q) {
|
||||
return pa.s < pb.s ? 1 : -1;
|
||||
} else {
|
||||
return pa.q < pb.q ? 1 : -1;
|
||||
}
|
||||
}).map(function(pair) {
|
||||
return pair[0];
|
||||
});
|
||||
|
||||
} else {
|
||||
return accept.sort(function (a, b) {
|
||||
// revsort
|
||||
return a.q < b.q ? 1 : -1;
|
||||
}).filter(function(type) {
|
||||
return type.q > 0;
|
||||
}).map(function(type) {
|
||||
return type.full;
|
||||
});
|
||||
}
|
||||
}
|
37
node_modules/errorhandler/node_modules/accepts/node_modules/negotiator/lib/negotiator.js
generated
vendored
100755
37
node_modules/errorhandler/node_modules/accepts/node_modules/negotiator/lib/negotiator.js
generated
vendored
100755
|
@ -0,0 +1,37 @@
|
|||
module.exports = Negotiator;
|
||||
Negotiator.Negotiator = Negotiator;
|
||||
|
||||
function Negotiator(request) {
|
||||
if (!(this instanceof Negotiator)) return new Negotiator(request);
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
var set = { charset: 'accept-charset',
|
||||
encoding: 'accept-encoding',
|
||||
language: 'accept-language',
|
||||
mediaType: 'accept' };
|
||||
|
||||
|
||||
function capitalize(string){
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
}
|
||||
|
||||
Object.keys(set).forEach(function (k) {
|
||||
var header = set[k],
|
||||
method = require('./'+k+'.js'),
|
||||
singular = k,
|
||||
plural = k + 's';
|
||||
|
||||
Negotiator.prototype[plural] = function (available) {
|
||||
return method(this.request.headers[header], available);
|
||||
};
|
||||
|
||||
Negotiator.prototype[singular] = function(available) {
|
||||
var set = this[plural](available);
|
||||
if (set) return set[0];
|
||||
};
|
||||
|
||||
// Keep preferred* methods for legacy compatibility
|
||||
Negotiator.prototype['preferred'+capitalize(plural)] = Negotiator.prototype[plural];
|
||||
Negotiator.prototype['preferred'+capitalize(singular)] = Negotiator.prototype[singular];
|
||||
})
|
49
node_modules/errorhandler/node_modules/accepts/node_modules/negotiator/package.json
generated
vendored
100755
49
node_modules/errorhandler/node_modules/accepts/node_modules/negotiator/package.json
generated
vendored
100755
|
@ -0,0 +1,49 @@
|
|||
{
|
||||
"name": "negotiator",
|
||||
"description": "HTTP content negotiation",
|
||||
"version": "0.4.7",
|
||||
"author": {
|
||||
"name": "Federico Romero",
|
||||
"email": "federico.romero@outboxlabs.com"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Isaac Z. Schlueter",
|
||||
"email": "i@izs.me",
|
||||
"url": "http://blog.izs.me/"
|
||||
}
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/federomero/negotiator.git"
|
||||
},
|
||||
"keywords": [
|
||||
"http",
|
||||
"content negotiation",
|
||||
"accept",
|
||||
"accept-language",
|
||||
"accept-encoding",
|
||||
"accept-charset"
|
||||
],
|
||||
"engine": "node >= 0.6",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"nodeunit": "0.8.x"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "nodeunit test"
|
||||
},
|
||||
"optionalDependencies": {},
|
||||
"engines": {
|
||||
"node": "*"
|
||||
},
|
||||
"main": "lib/negotiator.js",
|
||||
"readme": "# Negotiator [![Build Status](https://travis-ci.org/federomero/negotiator.png)](https://travis-ci.org/federomero/negotiator)\n\nAn HTTP content negotiator for node.js written in javascript.\n\n# Accept Negotiation\n\n Negotiator = require('negotiator')\n\n availableMediaTypes = ['text/html', 'text/plain', 'application/json']\n\n // The negotiator constructor receives a request object\n negotiator = new Negotiator(request)\n\n // Let's say Accept header is 'text/html, application/*;q=0.2, image/jpeg;q=0.8'\n\n negotiator.mediaTypes()\n // -> ['text/html', 'image/jpeg', 'application/*']\n\n negotiator.mediaTypes(availableMediaTypes)\n // -> ['text/html', 'application/json']\n\n negotiator.mediaType(availableMediaTypes)\n // -> 'text/html'\n\nYou can check a working example at `examples/accept.js`.\n\n## Methods\n\n`mediaTypes(availableMediaTypes)`:\n\nReturns an array of preferred media types ordered by priority from a list of available media types.\n\n`mediaType(availableMediaType)`:\n\nReturns the top preferred media type from a list of available media types.\n\n# Accept-Language Negotiation\n\n Negotiator = require('negotiator')\n\n negotiator = new Negotiator(request)\n\n availableLanguages = 'en', 'es', 'fr'\n\n // Let's say Accept-Language header is 'en;q=0.8, es, pt'\n\n negotiator.languages()\n // -> ['es', 'pt', 'en']\n\n negotiator.languages(availableLanguages)\n // -> ['es', 'en']\n\n language = negotiator.language(availableLanguages)\n // -> 'es'\n\nYou can check a working example at `examples/language.js`.\n\n## Methods\n\n`languages(availableLanguages)`:\n\nReturns an array of preferred languages ordered by priority from a list of available languages.\n\n`language(availableLanguages)`:\n\nReturns the top preferred language from a list of available languages.\n\n# Accept-Charset Negotiation\n\n Negotiator = require('negotiator')\n\n availableCharsets = ['utf-8', 'iso-8859-1', 'iso-8859-5']\n\n negotiator = new Negotiator(request)\n\n // Let's say Accept-Charset header is 'utf-8, iso-8859-1;q=0.8, utf-7;q=0.2'\n\n negotiator.charsets()\n // -> ['utf-8', 'iso-8859-1', 'utf-7']\n\n negotiator.charsets(availableCharsets)\n // -> ['utf-8', 'iso-8859-1']\n\n negotiator.charset(availableCharsets)\n // -> 'utf-8'\n\nYou can check a working example at `examples/charset.js`.\n\n## Methods\n\n`charsets(availableCharsets)`:\n\nReturns an array of preferred charsets ordered by priority from a list of available charsets.\n\n`charset(availableCharsets)`:\n\nReturns the top preferred charset from a list of available charsets.\n\n# Accept-Encoding Negotiation\n\n Negotiator = require('negotiator').Negotiator\n\n availableEncodings = ['identity', 'gzip']\n\n negotiator = new Negotiator(request)\n\n // Let's say Accept-Encoding header is 'gzip, compress;q=0.2, identity;q=0.5'\n\n negotiator.encodings()\n // -> ['gzip', 'identity', 'compress']\n\n negotiator.encodings(availableEncodings)\n // -> ['gzip', 'identity']\n\n negotiator.encoding(availableEncodings)\n // -> 'gzip'\n\nYou can check a working example at `examples/encoding.js`.\n\n## Methods\n\n`encodings(availableEncodings)`:\n\nReturns an array of preferred encodings ordered by priority from a list of available encodings.\n\n`encoding(availableEncodings)`:\n\nReturns the top preferred encoding from a list of available encodings.\n\n# License\n\nMIT\n",
|
||||
"readmeFilename": "readme.md",
|
||||
"bugs": {
|
||||
"url": "https://github.com/federomero/negotiator/issues"
|
||||
},
|
||||
"dependencies": {},
|
||||
"_id": "negotiator@0.4.7",
|
||||
"_from": "negotiator@0.4.7"
|
||||
}
|
132
node_modules/errorhandler/node_modules/accepts/node_modules/negotiator/readme.md
generated
vendored
100755
132
node_modules/errorhandler/node_modules/accepts/node_modules/negotiator/readme.md
generated
vendored
100755
|
@ -0,0 +1,132 @@
|
|||
# Negotiator [![Build Status](https://travis-ci.org/federomero/negotiator.png)](https://travis-ci.org/federomero/negotiator)
|
||||
|
||||
An HTTP content negotiator for node.js written in javascript.
|
||||
|
||||
# Accept Negotiation
|
||||
|
||||
Negotiator = require('negotiator')
|
||||
|
||||
availableMediaTypes = ['text/html', 'text/plain', 'application/json']
|
||||
|
||||
// The negotiator constructor receives a request object
|
||||
negotiator = new Negotiator(request)
|
||||
|
||||
// Let's say Accept header is 'text/html, application/*;q=0.2, image/jpeg;q=0.8'
|
||||
|
||||
negotiator.mediaTypes()
|
||||
// -> ['text/html', 'image/jpeg', 'application/*']
|
||||
|
||||
negotiator.mediaTypes(availableMediaTypes)
|
||||
// -> ['text/html', 'application/json']
|
||||
|
||||
negotiator.mediaType(availableMediaTypes)
|
||||
// -> 'text/html'
|
||||
|
||||
You can check a working example at `examples/accept.js`.
|
||||
|
||||
## Methods
|
||||
|
||||
`mediaTypes(availableMediaTypes)`:
|
||||
|
||||
Returns an array of preferred media types ordered by priority from a list of available media types.
|
||||
|
||||
`mediaType(availableMediaType)`:
|
||||
|
||||
Returns the top preferred media type from a list of available media types.
|
||||
|
||||
# Accept-Language Negotiation
|
||||
|
||||
Negotiator = require('negotiator')
|
||||
|
||||
negotiator = new Negotiator(request)
|
||||
|
||||
availableLanguages = 'en', 'es', 'fr'
|
||||
|
||||
// Let's say Accept-Language header is 'en;q=0.8, es, pt'
|
||||
|
||||
negotiator.languages()
|
||||
// -> ['es', 'pt', 'en']
|
||||
|
||||
negotiator.languages(availableLanguages)
|
||||
// -> ['es', 'en']
|
||||
|
||||
language = negotiator.language(availableLanguages)
|
||||
// -> 'es'
|
||||
|
||||
You can check a working example at `examples/language.js`.
|
||||
|
||||
## Methods
|
||||
|
||||
`languages(availableLanguages)`:
|
||||
|
||||
Returns an array of preferred languages ordered by priority from a list of available languages.
|
||||
|
||||
`language(availableLanguages)`:
|
||||
|
||||
Returns the top preferred language from a list of available languages.
|
||||
|
||||
# Accept-Charset Negotiation
|
||||
|
||||
Negotiator = require('negotiator')
|
||||
|
||||
availableCharsets = ['utf-8', 'iso-8859-1', 'iso-8859-5']
|
||||
|
||||
negotiator = new Negotiator(request)
|
||||
|
||||
// Let's say Accept-Charset header is 'utf-8, iso-8859-1;q=0.8, utf-7;q=0.2'
|
||||
|
||||
negotiator.charsets()
|
||||
// -> ['utf-8', 'iso-8859-1', 'utf-7']
|
||||
|
||||
negotiator.charsets(availableCharsets)
|
||||
// -> ['utf-8', 'iso-8859-1']
|
||||
|
||||
negotiator.charset(availableCharsets)
|
||||
// -> 'utf-8'
|
||||
|
||||
You can check a working example at `examples/charset.js`.
|
||||
|
||||
## Methods
|
||||
|
||||
`charsets(availableCharsets)`:
|
||||
|
||||
Returns an array of preferred charsets ordered by priority from a list of available charsets.
|
||||
|
||||
`charset(availableCharsets)`:
|
||||
|
||||
Returns the top preferred charset from a list of available charsets.
|
||||
|
||||
# Accept-Encoding Negotiation
|
||||
|
||||
Negotiator = require('negotiator').Negotiator
|
||||
|
||||
availableEncodings = ['identity', 'gzip']
|
||||
|
||||
negotiator = new Negotiator(request)
|
||||
|
||||
// Let's say Accept-Encoding header is 'gzip, compress;q=0.2, identity;q=0.5'
|
||||
|
||||
negotiator.encodings()
|
||||
// -> ['gzip', 'identity', 'compress']
|
||||
|
||||
negotiator.encodings(availableEncodings)
|
||||
// -> ['gzip', 'identity']
|
||||
|
||||
negotiator.encoding(availableEncodings)
|
||||
// -> 'gzip'
|
||||
|
||||
You can check a working example at `examples/encoding.js`.
|
||||
|
||||
## Methods
|
||||
|
||||
`encodings(availableEncodings)`:
|
||||
|
||||
Returns an array of preferred encodings ordered by priority from a list of available encodings.
|
||||
|
||||
`encoding(availableEncodings)`:
|
||||
|
||||
Returns the top preferred encoding from a list of available encodings.
|
||||
|
||||
# License
|
||||
|
||||
MIT
|
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
"name": "accepts",
|
||||
"description": "Higher-level content negotiation",
|
||||
"version": "1.0.6",
|
||||
"author": {
|
||||
"name": "Jonathan Ong",
|
||||
"email": "me@jongleberry.com",
|
||||
"url": "http://jongleberry.com"
|
||||
},
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/expressjs/accepts"
|
||||
},
|
||||
"dependencies": {
|
||||
"mime-types": "~1.0.0",
|
||||
"negotiator": "0.4.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"istanbul": "0.2.11",
|
||||
"mocha": "*",
|
||||
"should": "*"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha --require should --reporter dot test/",
|
||||
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --require should --reporter dot test/",
|
||||
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --require should --reporter spec test/"
|
||||
},
|
||||
"readme": "# Accepts\n\n[![NPM version](https://badge.fury.io/js/accepts.svg)](http://badge.fury.io/js/accepts)\n[![Build Status](https://travis-ci.org/expressjs/accepts.svg?branch=master)](https://travis-ci.org/expressjs/accepts)\n[![Coverage Status](https://img.shields.io/coveralls/expressjs/accepts.svg?branch=master)](https://coveralls.io/r/expressjs/accepts)\n\nHigher level content negotation based on [negotiator](https://github.com/federomero/negotiator). Extracted from [koa](https://github.com/koajs/koa) for general use.\n\nIn addition to negotatior, it allows:\n\n- Allows types as an array or arguments list, ie `(['text/html', 'application/json'])` as well as `('text/html', 'application/json')`.\n- Allows type shorthands such as `json`.\n- Returns `false` when no types match\n- Treats non-existent headers as `*`\n\n## API\n\n### var accept = new Accepts(req)\n\n```js\nvar accepts = require('accepts')\n\nhttp.createServer(function (req, res) {\n var accept = accepts(req)\n})\n```\n\n### accept\\[property\\]\\(\\)\n\nReturns all the explicitly accepted content property as an array in descending priority.\n\n- `accept.types()`\n- `accept.encodings()`\n- `accept.charsets()`\n- `accept.languages()`\n\nThey are also aliased in singular form such as `accept.type()`. `accept.languages()` is also aliased as `accept.langs()`, etc.\n\nNote: you should almost never do this in a real app as it defeats the purpose of content negotiation.\n\nExample:\n\n```js\n// in Google Chrome\nvar encodings = accept.encodings() // -> ['sdch', 'gzip', 'deflate']\n```\n\nSince you probably don't support `sdch`, you should just supply the encodings you support:\n\n```js\nvar encoding = accept.encodings('gzip', 'deflate') // -> 'gzip', probably\n```\n\n### accept\\[property\\]\\(values, ...\\)\n\nYou can either have `values` be an array or have an argument list of values.\n\nIf the client does not accept any `values`, `false` will be returned.\nIf the client accepts any `values`, the preferred `value` will be return.\n\nFor `accept.types()`, shorthand mime types are allowed.\n\nExample:\n\n```js\n// req.headers.accept = 'application/json'\n\naccept.types('json') // -> 'json'\naccept.types('html', 'json') // -> 'json'\naccept.types('html') // -> false\n\n// req.headers.accept = ''\n// which is equivalent to `*`\n\naccept.types() // -> [], no explicit types\naccept.types('text/html', 'text/json') // -> 'text/html', since it was first\n```\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2013 Jonathan Ong me@jongleberry.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.",
|
||||
"readmeFilename": "README.md",
|
||||
"bugs": {
|
||||
"url": "https://github.com/expressjs/accepts/issues"
|
||||
},
|
||||
"_id": "accepts@1.0.6",
|
||||
"_from": "accepts@~1.0.4"
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
components
|
||||
build
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
build: components index.js
|
||||
@component build
|
||||
|
||||
components:
|
||||
@Component install
|
||||
|
||||
clean:
|
||||
rm -fr build components template.js
|
||||
|
||||
.PHONY: clean
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
# escape-html
|
||||
|
||||
Escape HTML entities
|
||||
|
||||
## Example
|
||||
|
||||
```js
|
||||
var escape = require('escape-html');
|
||||
escape(str);
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"name": "escape-html",
|
||||
"description": "Escape HTML entities",
|
||||
"version": "1.0.1",
|
||||
"keywords": ["escape", "html", "utility"],
|
||||
"dependencies": {},
|
||||
"scripts": [
|
||||
"index.js"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
/**
|
||||
* Escape special characters in the given string of html.
|
||||
*
|
||||
* @param {String} html
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
module.exports = function(html) {
|
||||
return String(html)
|
||||
.replace(/&/g, '&')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>');
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"name": "escape-html",
|
||||
"description": "Escape HTML entities",
|
||||
"version": "1.0.1",
|
||||
"keywords": [
|
||||
"escape",
|
||||
"html",
|
||||
"utility"
|
||||
],
|
||||
"dependencies": {},
|
||||
"main": "index.js",
|
||||
"component": {
|
||||
"scripts": {
|
||||
"escape-html/index.js": "index.js"
|
||||
}
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/component/escape-html.git"
|
||||
},
|
||||
"readme": "\n# escape-html\n\n Escape HTML entities\n\n## Example\n\n```js\nvar escape = require('escape-html');\nescape(str);\n```\n\n## License\n\n MIT",
|
||||
"readmeFilename": "Readme.md",
|
||||
"bugs": {
|
||||
"url": "https://github.com/component/escape-html/issues"
|
||||
},
|
||||
"_id": "escape-html@1.0.1",
|
||||
"_from": "escape-html@1.0.1"
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"name": "errorhandler",
|
||||
"description": "connect's default error handler page",
|
||||
"version": "1.1.1",
|
||||
"author": {
|
||||
"name": "Jonathan Ong",
|
||||
"email": "me@jongleberry.com",
|
||||
"url": "http://jongleberry.com"
|
||||
},
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/expressjs/errorhandler"
|
||||
},
|
||||
"dependencies": {
|
||||
"accepts": "~1.0.4",
|
||||
"escape-html": "1.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"connect": "3",
|
||||
"istanbul": "0.2.10",
|
||||
"mocha": "~1.20.1",
|
||||
"should": "~4.0.1",
|
||||
"supertest": "~0.13.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha --reporter dot test/",
|
||||
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot test/",
|
||||
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec test/"
|
||||
},
|
||||
"readme": "# errorhandler\n\n[![NPM version](https://badge.fury.io/js/errorhandler.svg)](http://badge.fury.io/js/errorhandler)\n[![Build Status](https://travis-ci.org/expressjs/errorhandler.svg?branch=master)](https://travis-ci.org/expressjs/errorhandler)\n[![Coverage Status](https://img.shields.io/coveralls/expressjs/errorhandler.svg?branch=master)](https://coveralls.io/r/expressjs/errorhandler)\n\nPreviously `connect.errorHandler()`.\n\n## Install\n\n```sh\n$ npm install errorhandler\n```\n\n## API\n\n### errorhandler()\n\nCreate new middleware to handle errors and respond with content negotiation.\nThis middleware is only intended to be used in a development environment, as\nthe full error stack traces will be send back to the client when an error\noccurs.\n\n## Example\n\n```js\nvar connect = require('connect')\nvar errorhandler = require('errorhandler')\n\nvar app = connect()\n\nif (process.env.NODE_ENV === 'development') {\n app.use(errorhandler())\n}\n```\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2014 Jonathan Ong me@jongleberry.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n",
|
||||
"readmeFilename": "README.md",
|
||||
"bugs": {
|
||||
"url": "https://github.com/expressjs/errorhandler/issues"
|
||||
},
|
||||
"_id": "errorhandler@1.1.1",
|
||||
"_from": "errorhandler@"
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset='utf-8'>
|
||||
<title>{error}</title>
|
||||
<style>{style}</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="wrapper">
|
||||
<h1>{title}</h1>
|
||||
<h2><em>{statusCode}</em> {error}</h2>
|
||||
<ul id="stacktrace">{stack}</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,35 @@
|
|||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
outline: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
padding: 80px 100px;
|
||||
font: 13px "Helvetica Neue", "Lucida Grande", "Arial";
|
||||
background: #ECE9E9 -webkit-gradient(linear, 0% 0%, 0% 100%, from(#fff), to(#ECE9E9));
|
||||
background: #ECE9E9 -moz-linear-gradient(top, #fff, #ECE9E9);
|
||||
background-repeat: no-repeat;
|
||||
color: #555;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
h1, h2 {
|
||||
font-size: 22px;
|
||||
color: #343434;
|
||||
}
|
||||
h1 em, h2 em {
|
||||
padding: 0 5px;
|
||||
font-weight: normal;
|
||||
}
|
||||
h1 {
|
||||
font-size: 60px;
|
||||
}
|
||||
h2 {
|
||||
margin-top: 10px;
|
||||
}
|
||||
ul li {
|
||||
list-style: none;
|
||||
}
|
||||
#stacktrace {
|
||||
margin-left: 60px;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
.git*
|
||||
benchmarks/
|
||||
coverage/
|
||||
docs/
|
||||
examples/
|
||||
support/
|
||||
test/
|
||||
testing.js
|
||||
.DS_Store
|
||||
.travis.yml
|
||||
Contributing.md
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,22 @@
|
|||
(The MIT License)
|
||||
|
||||
Copyright (c) 2009-2014 TJ Holowaychuk <tj@vision-media.ca>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,113 @@
|
|||
[![express logo](https://i.cloudup.com/zfY6lL7eFa-3000x3000.png)](http://expressjs.com/)
|
||||
|
||||
Fast, unopinionated, minimalist web framework for [node](http://nodejs.org).
|
||||
|
||||
[![NPM version](https://badge.fury.io/js/express.svg)](http://badge.fury.io/js/express)
|
||||
[![Build Status](https://travis-ci.org/visionmedia/express.svg?branch=master)](https://travis-ci.org/visionmedia/express)
|
||||
[![Coverage Status](https://img.shields.io/coveralls/visionmedia/express.svg)](https://coveralls.io/r/visionmedia/express)
|
||||
[![Gittip](http://img.shields.io/gittip/visionmedia.svg)](https://www.gittip.com/visionmedia/)
|
||||
|
||||
```js
|
||||
var express = require('express');
|
||||
var app = express();
|
||||
|
||||
app.get('/', function(req, res){
|
||||
res.send('Hello World');
|
||||
});
|
||||
|
||||
app.listen(3000);
|
||||
```
|
||||
|
||||
**PROTIP** Be sure to read [Migrating from 3.x to 4.x](https://github.com/visionmedia/express/wiki/Migrating-from-3.x-to-4.x) as well as [New features in 4.x](https://github.com/visionmedia/express/wiki/New-features-in-4.x).
|
||||
|
||||
## Installation
|
||||
|
||||
$ npm install express
|
||||
|
||||
## Quick Start
|
||||
|
||||
The quickest way to get started with express is to utilize the executable [`express(1)`](http://github.com/expressjs/generator) to generate an application as shown below:
|
||||
|
||||
Install the executable. The executable's major version will match Express's:
|
||||
|
||||
$ npm install -g express-generator@3
|
||||
|
||||
Create the app:
|
||||
|
||||
$ express /tmp/foo && cd /tmp/foo
|
||||
|
||||
Install dependencies:
|
||||
|
||||
$ npm install
|
||||
|
||||
Start the server:
|
||||
|
||||
$ npm start
|
||||
|
||||
## Features
|
||||
|
||||
* Robust routing
|
||||
* HTTP helpers (redirection, caching, etc)
|
||||
* View system supporting 14+ template engines
|
||||
* Content negotiation
|
||||
* Focus on high performance
|
||||
* Executable for generating applications quickly
|
||||
* High test coverage
|
||||
|
||||
## Philosophy
|
||||
|
||||
The Express philosophy is to provide small, robust tooling for HTTP servers, making
|
||||
it a great solution for single page applications, web sites, hybrids, or public
|
||||
HTTP APIs.
|
||||
|
||||
Express does not force you to use any specific ORM or template engine. With support for over
|
||||
14 template engines via [Consolidate.js](http://github.com/visionmedia/consolidate.js),
|
||||
you can quickly craft your perfect framework.
|
||||
|
||||
## More Information
|
||||
|
||||
* [Website and Documentation](http://expressjs.com/) stored at [visionmedia/expressjs.com](https://github.com/visionmedia/expressjs.com)
|
||||
* Join #express on freenode
|
||||
* [Google Group](http://groups.google.com/group/express-js) for discussion
|
||||
* Follow [tjholowaychuk](http://twitter.com/tjholowaychuk) and [defunctzombie](https://twitter.com/defunctzombie) on twitter for updates
|
||||
* Visit the [Wiki](http://github.com/visionmedia/express/wiki)
|
||||
* [Русскоязычная документация](http://jsman.ru/express/)
|
||||
* Run express examples [online](https://runnable.com/express)
|
||||
|
||||
## Viewing Examples
|
||||
|
||||
Clone the Express repo, then install the dev dependencies to install all the example / test suite dependencies:
|
||||
|
||||
$ git clone git://github.com/visionmedia/express.git --depth 1
|
||||
$ cd express
|
||||
$ npm install
|
||||
|
||||
Then run whichever tests you want:
|
||||
|
||||
$ node examples/content-negotiation
|
||||
|
||||
You can also view live examples here:
|
||||
|
||||
<a href="https://runnable.com/express" target="_blank"><img src="https://runnable.com/external/styles/assets/runnablebtn.png" style="width:67px;height:25px;"></a>
|
||||
|
||||
## Running Tests
|
||||
|
||||
To run the test suite, first invoke the following command within the repo, installing the development dependencies:
|
||||
|
||||
$ npm install
|
||||
|
||||
Then run the tests:
|
||||
|
||||
```sh
|
||||
$ npm test
|
||||
```
|
||||
|
||||
## Contributors
|
||||
|
||||
Author: [TJ Holowaychuk](http://github.com/visionmedia)
|
||||
Lead Maintainer: [Roman Shtylman](https://github.com/defunctzombie)
|
||||
Contributors: https://github.com/visionmedia/express/graphs/contributors
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
module.exports = require('./lib/express');
|
|
@ -0,0 +1,549 @@
|
|||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var mixin = require('utils-merge');
|
||||
var escapeHtml = require('escape-html');
|
||||
var Router = require('./router');
|
||||
var methods = require('methods');
|
||||
var middleware = require('./middleware/init');
|
||||
var query = require('./middleware/query');
|
||||
var debug = require('debug')('express:application');
|
||||
var View = require('./view');
|
||||
var http = require('http');
|
||||
var compileETag = require('./utils').compileETag;
|
||||
var compileTrust = require('./utils').compileTrust;
|
||||
var deprecate = require('./utils').deprecate;
|
||||
var resolve = require('path').resolve;
|
||||
|
||||
/**
|
||||
* Application prototype.
|
||||
*/
|
||||
|
||||
var app = exports = module.exports = {};
|
||||
|
||||
/**
|
||||
* Initialize the server.
|
||||
*
|
||||
* - setup default configuration
|
||||
* - setup default middleware
|
||||
* - setup route reflection methods
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
app.init = function(){
|
||||
this.cache = {};
|
||||
this.settings = {};
|
||||
this.engines = {};
|
||||
this.defaultConfiguration();
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize application configuration.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
app.defaultConfiguration = function(){
|
||||
// default settings
|
||||
this.enable('x-powered-by');
|
||||
this.set('etag', 'weak');
|
||||
var env = process.env.NODE_ENV || 'development';
|
||||
this.set('env', env);
|
||||
this.set('subdomain offset', 2);
|
||||
this.set('trust proxy', false);
|
||||
|
||||
debug('booting in %s mode', env);
|
||||
|
||||
// inherit protos
|
||||
this.on('mount', function(parent){
|
||||
this.request.__proto__ = parent.request;
|
||||
this.response.__proto__ = parent.response;
|
||||
this.engines.__proto__ = parent.engines;
|
||||
this.settings.__proto__ = parent.settings;
|
||||
});
|
||||
|
||||
// setup locals
|
||||
this.locals = Object.create(null);
|
||||
|
||||
// top-most app is mounted at /
|
||||
this.mountpath = '/';
|
||||
|
||||
// default locals
|
||||
this.locals.settings = this.settings;
|
||||
|
||||
// default configuration
|
||||
this.set('view', View);
|
||||
this.set('views', resolve('views'));
|
||||
this.set('jsonp callback name', 'callback');
|
||||
|
||||
if (env === 'production') {
|
||||
this.enable('view cache');
|
||||
}
|
||||
|
||||
Object.defineProperty(this, 'router', {
|
||||
get: function() {
|
||||
throw new Error('\'app.router\' is deprecated!\nPlease see the 3.x to 4.x migration guide for details on how to update your app.');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* lazily adds the base router if it has not yet been added.
|
||||
*
|
||||
* We cannot add the base router in the defaultConfiguration because
|
||||
* it reads app settings which might be set after that has run.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
app.lazyrouter = function() {
|
||||
if (!this._router) {
|
||||
this._router = new Router({
|
||||
caseSensitive: this.enabled('case sensitive routing'),
|
||||
strict: this.enabled('strict routing')
|
||||
});
|
||||
|
||||
this._router.use(query());
|
||||
this._router.use(middleware.init(this));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Dispatch a req, res pair into the application. Starts pipeline processing.
|
||||
*
|
||||
* If no _done_ callback is provided, then default error handlers will respond
|
||||
* in the event of an error bubbling through the stack.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
app.handle = function(req, res, done) {
|
||||
var env = this.get('env');
|
||||
|
||||
this._router.handle(req, res, function(err) {
|
||||
if (done) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
// unhandled error
|
||||
if (err) {
|
||||
// default to 500
|
||||
if (res.statusCode < 400) res.statusCode = 500;
|
||||
debug('default %s', res.statusCode);
|
||||
|
||||
// respect err.status
|
||||
if (err.status) res.statusCode = err.status;
|
||||
|
||||
// production gets a basic error message
|
||||
var msg = 'production' == env
|
||||
? http.STATUS_CODES[res.statusCode]
|
||||
: err.stack || err.toString();
|
||||
msg = escapeHtml(msg);
|
||||
|
||||
// log to stderr in a non-test env
|
||||
if ('test' != env) console.error(err.stack || err.toString());
|
||||
if (res.headersSent) return req.socket.destroy();
|
||||
res.setHeader('Content-Type', 'text/html');
|
||||
res.setHeader('Content-Length', Buffer.byteLength(msg));
|
||||
if ('HEAD' == req.method) return res.end();
|
||||
res.end(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
// 404
|
||||
debug('default 404');
|
||||
res.statusCode = 404;
|
||||
res.setHeader('Content-Type', 'text/html');
|
||||
if ('HEAD' == req.method) return res.end();
|
||||
res.end('Cannot ' + escapeHtml(req.method) + ' ' + escapeHtml(req.originalUrl) + '\n');
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Proxy `Router#use()` to add middleware to the app router.
|
||||
* See Router#use() documentation for details.
|
||||
*
|
||||
* If the _fn_ parameter is an express app, then it will be
|
||||
* mounted at the _route_ specified.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
app.use = function(route, fn){
|
||||
var mount_app;
|
||||
|
||||
// default route to '/'
|
||||
if ('string' != typeof route) fn = route, route = '/';
|
||||
|
||||
// express app
|
||||
if (fn.handle && fn.set) mount_app = fn;
|
||||
|
||||
// restore .app property on req and res
|
||||
if (mount_app) {
|
||||
debug('.use app under %s', route);
|
||||
mount_app.mountpath = route;
|
||||
fn = function(req, res, next) {
|
||||
var orig = req.app;
|
||||
mount_app.handle(req, res, function(err) {
|
||||
req.__proto__ = orig.request;
|
||||
res.__proto__ = orig.response;
|
||||
next(err);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
this.lazyrouter();
|
||||
this._router.use(route, fn);
|
||||
|
||||
// mounted an app
|
||||
if (mount_app) {
|
||||
mount_app.parent = this;
|
||||
mount_app.emit('mount', this);
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Proxy to the app `Router#route()`
|
||||
* Returns a new `Route` instance for the _path_.
|
||||
*
|
||||
* Routes are isolated middleware stacks for specific paths.
|
||||
* See the Route api docs for details.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
app.route = function(path){
|
||||
this.lazyrouter();
|
||||
return this._router.route(path);
|
||||
};
|
||||
|
||||
/**
|
||||
* Register the given template engine callback `fn`
|
||||
* as `ext`.
|
||||
*
|
||||
* By default will `require()` the engine based on the
|
||||
* file extension. For example if you try to render
|
||||
* a "foo.jade" file Express will invoke the following internally:
|
||||
*
|
||||
* app.engine('jade', require('jade').__express);
|
||||
*
|
||||
* For engines that do not provide `.__express` out of the box,
|
||||
* or if you wish to "map" a different extension to the template engine
|
||||
* you may use this method. For example mapping the EJS template engine to
|
||||
* ".html" files:
|
||||
*
|
||||
* app.engine('html', require('ejs').renderFile);
|
||||
*
|
||||
* In this case EJS provides a `.renderFile()` method with
|
||||
* the same signature that Express expects: `(path, options, callback)`,
|
||||
* though note that it aliases this method as `ejs.__express` internally
|
||||
* so if you're using ".ejs" extensions you dont need to do anything.
|
||||
*
|
||||
* Some template engines do not follow this convention, the
|
||||
* [Consolidate.js](https://github.com/visionmedia/consolidate.js)
|
||||
* library was created to map all of node's popular template
|
||||
* engines to follow this convention, thus allowing them to
|
||||
* work seamlessly within Express.
|
||||
*
|
||||
* @param {String} ext
|
||||
* @param {Function} fn
|
||||
* @return {app} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
app.engine = function(ext, fn){
|
||||
if ('function' != typeof fn) throw new Error('callback function required');
|
||||
if ('.' != ext[0]) ext = '.' + ext;
|
||||
this.engines[ext] = fn;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Proxy to `Router#param()` with one added api feature. The _name_ parameter
|
||||
* can be an array of names.
|
||||
*
|
||||
* See the Router#param() docs for more details.
|
||||
*
|
||||
* @param {String|Array} name
|
||||
* @param {Function} fn
|
||||
* @return {app} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
app.param = function(name, fn){
|
||||
var self = this;
|
||||
self.lazyrouter();
|
||||
|
||||
if (Array.isArray(name)) {
|
||||
name.forEach(function(key) {
|
||||
self.param(key, fn);
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
self._router.param(name, fn);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Assign `setting` to `val`, or return `setting`'s value.
|
||||
*
|
||||
* app.set('foo', 'bar');
|
||||
* app.get('foo');
|
||||
* // => "bar"
|
||||
*
|
||||
* Mounted servers inherit their parent server's settings.
|
||||
*
|
||||
* @param {String} setting
|
||||
* @param {*} [val]
|
||||
* @return {Server} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
app.set = function(setting, val){
|
||||
if (arguments.length === 1) {
|
||||
// app.get(setting)
|
||||
return this.settings[setting];
|
||||
}
|
||||
|
||||
// set value
|
||||
this.settings[setting] = val;
|
||||
|
||||
// trigger matched settings
|
||||
switch (setting) {
|
||||
case 'etag':
|
||||
debug('compile etag %s', val);
|
||||
this.set('etag fn', compileETag(val));
|
||||
break;
|
||||
case 'trust proxy':
|
||||
debug('compile trust proxy %s', val);
|
||||
this.set('trust proxy fn', compileTrust(val));
|
||||
break;
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the app's absolute pathname
|
||||
* based on the parent(s) that have
|
||||
* mounted it.
|
||||
*
|
||||
* For example if the application was
|
||||
* mounted as "/admin", which itself
|
||||
* was mounted as "/blog" then the
|
||||
* return value would be "/blog/admin".
|
||||
*
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
app.path = function(){
|
||||
return this.parent
|
||||
? this.parent.path() + this.mountpath
|
||||
: '';
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if `setting` is enabled (truthy).
|
||||
*
|
||||
* app.enabled('foo')
|
||||
* // => false
|
||||
*
|
||||
* app.enable('foo')
|
||||
* app.enabled('foo')
|
||||
* // => true
|
||||
*
|
||||
* @param {String} setting
|
||||
* @return {Boolean}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
app.enabled = function(setting){
|
||||
return !!this.set(setting);
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if `setting` is disabled.
|
||||
*
|
||||
* app.disabled('foo')
|
||||
* // => true
|
||||
*
|
||||
* app.enable('foo')
|
||||
* app.disabled('foo')
|
||||
* // => false
|
||||
*
|
||||
* @param {String} setting
|
||||
* @return {Boolean}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
app.disabled = function(setting){
|
||||
return !this.set(setting);
|
||||
};
|
||||
|
||||
/**
|
||||
* Enable `setting`.
|
||||
*
|
||||
* @param {String} setting
|
||||
* @return {app} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
app.enable = function(setting){
|
||||
return this.set(setting, true);
|
||||
};
|
||||
|
||||
/**
|
||||
* Disable `setting`.
|
||||
*
|
||||
* @param {String} setting
|
||||
* @return {app} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
app.disable = function(setting){
|
||||
return this.set(setting, false);
|
||||
};
|
||||
|
||||
/**
|
||||
* Delegate `.VERB(...)` calls to `router.VERB(...)`.
|
||||
*/
|
||||
|
||||
methods.forEach(function(method){
|
||||
app[method] = function(path){
|
||||
if ('get' == method && 1 == arguments.length) return this.set(path);
|
||||
|
||||
this.lazyrouter();
|
||||
|
||||
var route = this._router.route(path);
|
||||
route[method].apply(route, [].slice.call(arguments, 1));
|
||||
return this;
|
||||
};
|
||||
});
|
||||
|
||||
/**
|
||||
* Special-cased "all" method, applying the given route `path`,
|
||||
* middleware, and callback to _every_ HTTP method.
|
||||
*
|
||||
* @param {String} path
|
||||
* @param {Function} ...
|
||||
* @return {app} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
app.all = function(path){
|
||||
this.lazyrouter();
|
||||
|
||||
var route = this._router.route(path);
|
||||
var args = [].slice.call(arguments, 1);
|
||||
methods.forEach(function(method){
|
||||
route[method].apply(route, args);
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
// del -> delete alias
|
||||
|
||||
app.del = deprecate(app.delete, 'app.del: Use app.delete instead');
|
||||
|
||||
/**
|
||||
* Render the given view `name` name with `options`
|
||||
* and a callback accepting an error and the
|
||||
* rendered template string.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* app.render('email', { name: 'Tobi' }, function(err, html){
|
||||
* // ...
|
||||
* })
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {String|Function} options or fn
|
||||
* @param {Function} fn
|
||||
* @api public
|
||||
*/
|
||||
|
||||
app.render = function(name, options, fn){
|
||||
var opts = {};
|
||||
var cache = this.cache;
|
||||
var engines = this.engines;
|
||||
var view;
|
||||
|
||||
// support callback function as second arg
|
||||
if ('function' == typeof options) {
|
||||
fn = options, options = {};
|
||||
}
|
||||
|
||||
// merge app.locals
|
||||
mixin(opts, this.locals);
|
||||
|
||||
// merge options._locals
|
||||
if (options._locals) mixin(opts, options._locals);
|
||||
|
||||
// merge options
|
||||
mixin(opts, options);
|
||||
|
||||
// set .cache unless explicitly provided
|
||||
opts.cache = null == opts.cache
|
||||
? this.enabled('view cache')
|
||||
: opts.cache;
|
||||
|
||||
// primed cache
|
||||
if (opts.cache) view = cache[name];
|
||||
|
||||
// view
|
||||
if (!view) {
|
||||
view = new (this.get('view'))(name, {
|
||||
defaultEngine: this.get('view engine'),
|
||||
root: this.get('views'),
|
||||
engines: engines
|
||||
});
|
||||
|
||||
if (!view.path) {
|
||||
var err = new Error('Failed to lookup view "' + name + '" in views directory "' + view.root + '"');
|
||||
err.view = view;
|
||||
return fn(err);
|
||||
}
|
||||
|
||||
// prime the cache
|
||||
if (opts.cache) cache[name] = view;
|
||||
}
|
||||
|
||||
// render
|
||||
try {
|
||||
view.render(opts, fn);
|
||||
} catch (err) {
|
||||
fn(err);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Listen for connections.
|
||||
*
|
||||
* A node `http.Server` is returned, with this
|
||||
* application (which is a `Function`) as its
|
||||
* callback. If you wish to create both an HTTP
|
||||
* and HTTPS server you may do so with the "http"
|
||||
* and "https" modules as shown here:
|
||||
*
|
||||
* var http = require('http')
|
||||
* , https = require('https')
|
||||
* , express = require('express')
|
||||
* , app = express();
|
||||
*
|
||||
* http.createServer(app).listen(80);
|
||||
* https.createServer({ ... }, app).listen(443);
|
||||
*
|
||||
* @return {http.Server}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
app.listen = function(){
|
||||
var server = http.createServer(this);
|
||||
return server.listen.apply(server, arguments);
|
||||
};
|
|
@ -0,0 +1,93 @@
|
|||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var mixin = require('utils-merge');
|
||||
var proto = require('./application');
|
||||
var Route = require('./router/route');
|
||||
var Router = require('./router');
|
||||
var req = require('./request');
|
||||
var res = require('./response');
|
||||
|
||||
/**
|
||||
* Expose `createApplication()`.
|
||||
*/
|
||||
|
||||
exports = module.exports = createApplication;
|
||||
|
||||
/**
|
||||
* Create an express application.
|
||||
*
|
||||
* @return {Function}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function createApplication() {
|
||||
var app = function(req, res, next) {
|
||||
app.handle(req, res, next);
|
||||
};
|
||||
|
||||
mixin(app, proto);
|
||||
mixin(app, EventEmitter.prototype);
|
||||
|
||||
app.request = { __proto__: req, app: app };
|
||||
app.response = { __proto__: res, app: app };
|
||||
app.init();
|
||||
return app;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose the prototypes.
|
||||
*/
|
||||
|
||||
exports.application = proto;
|
||||
exports.request = req;
|
||||
exports.response = res;
|
||||
|
||||
/**
|
||||
* Expose constructors.
|
||||
*/
|
||||
|
||||
exports.Route = Route;
|
||||
exports.Router = Router;
|
||||
|
||||
/**
|
||||
* Expose middleware
|
||||
*/
|
||||
|
||||
exports.query = require('./middleware/query');
|
||||
exports.static = require('serve-static');
|
||||
|
||||
/**
|
||||
* Replace removed middleware with an appropriate error message.
|
||||
*/
|
||||
|
||||
[
|
||||
'json',
|
||||
'urlencoded',
|
||||
'bodyParser',
|
||||
'compress',
|
||||
'cookieSession',
|
||||
'session',
|
||||
'logger',
|
||||
'cookieParser',
|
||||
'favicon',
|
||||
'responseTime',
|
||||
'errorHandler',
|
||||
'timeout',
|
||||
'methodOverride',
|
||||
'vhost',
|
||||
'csrf',
|
||||
'directory',
|
||||
'limit',
|
||||
'multipart',
|
||||
'staticCache',
|
||||
].forEach(function (name) {
|
||||
Object.defineProperty(exports, name, {
|
||||
get: function () {
|
||||
throw new Error('Most middleware (like ' + name + ') is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.');
|
||||
},
|
||||
configurable: true
|
||||
});
|
||||
});
|
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
* Initialization middleware, exposing the
|
||||
* request and response to eachother, as well
|
||||
* as defaulting the X-Powered-By header field.
|
||||
*
|
||||
* @param {Function} app
|
||||
* @return {Function}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.init = function(app){
|
||||
return function expressInit(req, res, next){
|
||||
if (app.enabled('x-powered-by')) res.setHeader('X-Powered-By', 'Express');
|
||||
req.res = res;
|
||||
res.req = req;
|
||||
req.next = next;
|
||||
|
||||
req.__proto__ = app.request;
|
||||
res.__proto__ = app.response;
|
||||
|
||||
res.locals = res.locals || Object.create(null);
|
||||
|
||||
next();
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var qs = require('qs');
|
||||
var parseUrl = require('parseurl');
|
||||
|
||||
/**
|
||||
* Query:
|
||||
*
|
||||
* Automatically parse the query-string when available,
|
||||
* populating the `req.query` object using
|
||||
* [qs](https://github.com/visionmedia/node-querystring).
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* .use(connect.query())
|
||||
* .use(function(req, res){
|
||||
* res.end(JSON.stringify(req.query));
|
||||
* });
|
||||
*
|
||||
* The `options` passed are provided to qs.parse function.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @return {Function}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
module.exports = function query(options){
|
||||
return function query(req, res, next){
|
||||
if (!req.query) {
|
||||
req.query = ~req.url.indexOf('?')
|
||||
? qs.parse(parseUrl(req).query, options)
|
||||
: {};
|
||||
}
|
||||
|
||||
next();
|
||||
};
|
||||
};
|
|
@ -0,0 +1,426 @@
|
|||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var accepts = require('accepts');
|
||||
var typeis = require('type-is');
|
||||
var http = require('http');
|
||||
var fresh = require('fresh');
|
||||
var parseRange = require('range-parser');
|
||||
var parse = require('parseurl');
|
||||
var proxyaddr = require('proxy-addr');
|
||||
|
||||
/**
|
||||
* Request prototype.
|
||||
*/
|
||||
|
||||
var req = exports = module.exports = {
|
||||
__proto__: http.IncomingMessage.prototype
|
||||
};
|
||||
|
||||
/**
|
||||
* Return request header.
|
||||
*
|
||||
* The `Referrer` header field is special-cased,
|
||||
* both `Referrer` and `Referer` are interchangeable.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* req.get('Content-Type');
|
||||
* // => "text/plain"
|
||||
*
|
||||
* req.get('content-type');
|
||||
* // => "text/plain"
|
||||
*
|
||||
* req.get('Something');
|
||||
* // => undefined
|
||||
*
|
||||
* Aliased as `req.header()`.
|
||||
*
|
||||
* @param {String} name
|
||||
* @return {String}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
req.get =
|
||||
req.header = function(name){
|
||||
switch (name = name.toLowerCase()) {
|
||||
case 'referer':
|
||||
case 'referrer':
|
||||
return this.headers.referrer
|
||||
|| this.headers.referer;
|
||||
default:
|
||||
return this.headers[name];
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* To do: update docs.
|
||||
*
|
||||
* Check if the given `type(s)` is acceptable, returning
|
||||
* the best match when true, otherwise `undefined`, in which
|
||||
* case you should respond with 406 "Not Acceptable".
|
||||
*
|
||||
* The `type` value may be a single mime type string
|
||||
* such as "application/json", the extension name
|
||||
* such as "json", a comma-delimted list such as "json, html, text/plain",
|
||||
* an argument list such as `"json", "html", "text/plain"`,
|
||||
* or an array `["json", "html", "text/plain"]`. When a list
|
||||
* or array is given the _best_ match, if any is returned.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* // Accept: text/html
|
||||
* req.accepts('html');
|
||||
* // => "html"
|
||||
*
|
||||
* // Accept: text/*, application/json
|
||||
* req.accepts('html');
|
||||
* // => "html"
|
||||
* req.accepts('text/html');
|
||||
* // => "text/html"
|
||||
* req.accepts('json, text');
|
||||
* // => "json"
|
||||
* req.accepts('application/json');
|
||||
* // => "application/json"
|
||||
*
|
||||
* // Accept: text/*, application/json
|
||||
* req.accepts('image/png');
|
||||
* req.accepts('png');
|
||||
* // => undefined
|
||||
*
|
||||
* // Accept: text/*;q=.5, application/json
|
||||
* req.accepts(['html', 'json']);
|
||||
* req.accepts('html', 'json');
|
||||
* req.accepts('html, json');
|
||||
* // => "json"
|
||||
*
|
||||
* @param {String|Array} type(s)
|
||||
* @return {String}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
req.accepts = function(){
|
||||
var accept = accepts(this);
|
||||
return accept.types.apply(accept, arguments);
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if the given `encoding` is accepted.
|
||||
*
|
||||
* @param {String} encoding
|
||||
* @return {Boolean}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
req.acceptsEncoding = // backwards compatibility
|
||||
req.acceptsEncodings = function(){
|
||||
var accept = accepts(this);
|
||||
return accept.encodings.apply(accept, arguments);
|
||||
};
|
||||
|
||||
/**
|
||||
* To do: update docs.
|
||||
*
|
||||
* Check if the given `charset` is acceptable,
|
||||
* otherwise you should respond with 406 "Not Acceptable".
|
||||
*
|
||||
* @param {String} charset
|
||||
* @return {Boolean}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
req.acceptsCharset = // backwards compatibility
|
||||
req.acceptsCharsets = function(){
|
||||
var accept = accepts(this);
|
||||
return accept.charsets.apply(accept, arguments);
|
||||
};
|
||||
|
||||
/**
|
||||
* To do: update docs.
|
||||
*
|
||||
* Check if the given `lang` is acceptable,
|
||||
* otherwise you should respond with 406 "Not Acceptable".
|
||||
*
|
||||
* @param {String} lang
|
||||
* @return {Boolean}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
req.acceptsLanguage = // backwards compatibility
|
||||
req.acceptsLanguages = function(){
|
||||
var accept = accepts(this);
|
||||
return accept.languages.apply(accept, arguments);
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse Range header field,
|
||||
* capping to the given `size`.
|
||||
*
|
||||
* Unspecified ranges such as "0-" require
|
||||
* knowledge of your resource length. In
|
||||
* the case of a byte range this is of course
|
||||
* the total number of bytes. If the Range
|
||||
* header field is not given `null` is returned,
|
||||
* `-1` when unsatisfiable, `-2` when syntactically invalid.
|
||||
*
|
||||
* NOTE: remember that ranges are inclusive, so
|
||||
* for example "Range: users=0-3" should respond
|
||||
* with 4 users when available, not 3.
|
||||
*
|
||||
* @param {Number} size
|
||||
* @return {Array}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
req.range = function(size){
|
||||
var range = this.get('Range');
|
||||
if (!range) return;
|
||||
return parseRange(size, range);
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the value of param `name` when present or `defaultValue`.
|
||||
*
|
||||
* - Checks route placeholders, ex: _/user/:id_
|
||||
* - Checks body params, ex: id=12, {"id":12}
|
||||
* - Checks query string params, ex: ?id=12
|
||||
*
|
||||
* To utilize request bodies, `req.body`
|
||||
* should be an object. This can be done by using
|
||||
* the `bodyParser()` middleware.
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {Mixed} [defaultValue]
|
||||
* @return {String}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
req.param = function(name, defaultValue){
|
||||
var params = this.params || {};
|
||||
var body = this.body || {};
|
||||
var query = this.query || {};
|
||||
if (null != params[name] && params.hasOwnProperty(name)) return params[name];
|
||||
if (null != body[name]) return body[name];
|
||||
if (null != query[name]) return query[name];
|
||||
return defaultValue;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if the incoming request contains the "Content-Type"
|
||||
* header field, and it contains the give mime `type`.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* // With Content-Type: text/html; charset=utf-8
|
||||
* req.is('html');
|
||||
* req.is('text/html');
|
||||
* req.is('text/*');
|
||||
* // => true
|
||||
*
|
||||
* // When Content-Type is application/json
|
||||
* req.is('json');
|
||||
* req.is('application/json');
|
||||
* req.is('application/*');
|
||||
* // => true
|
||||
*
|
||||
* req.is('html');
|
||||
* // => false
|
||||
*
|
||||
* @param {String} type
|
||||
* @return {Boolean}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
req.is = function(types){
|
||||
if (!Array.isArray(types)) types = [].slice.call(arguments);
|
||||
return typeis(this, types);
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the protocol string "http" or "https"
|
||||
* when requested with TLS. When the "trust proxy"
|
||||
* setting trusts the socket address, the
|
||||
* "X-Forwarded-Proto" header field will be trusted.
|
||||
* If you're running behind a reverse proxy that
|
||||
* supplies https for you this may be enabled.
|
||||
*
|
||||
* @return {String}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
req.__defineGetter__('protocol', function(){
|
||||
var trust = this.app.get('trust proxy fn');
|
||||
|
||||
if (!trust(this.connection.remoteAddress)) {
|
||||
return this.connection.encrypted
|
||||
? 'https'
|
||||
: 'http';
|
||||
}
|
||||
|
||||
// Note: X-Forwarded-Proto is normally only ever a
|
||||
// single value, but this is to be safe.
|
||||
var proto = this.get('X-Forwarded-Proto') || 'http';
|
||||
return proto.split(/\s*,\s*/)[0];
|
||||
});
|
||||
|
||||
/**
|
||||
* Short-hand for:
|
||||
*
|
||||
* req.protocol == 'https'
|
||||
*
|
||||
* @return {Boolean}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
req.__defineGetter__('secure', function(){
|
||||
return 'https' == this.protocol;
|
||||
});
|
||||
|
||||
/**
|
||||
* Return the remote address from the trusted proxy.
|
||||
*
|
||||
* The is the remote address on the socket unless
|
||||
* "trust proxy" is set.
|
||||
*
|
||||
* @return {String}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
req.__defineGetter__('ip', function(){
|
||||
var trust = this.app.get('trust proxy fn');
|
||||
return proxyaddr(this, trust);
|
||||
});
|
||||
|
||||
/**
|
||||
* When "trust proxy" is set, trusted proxy addresses + client.
|
||||
*
|
||||
* For example if the value were "client, proxy1, proxy2"
|
||||
* you would receive the array `["client", "proxy1", "proxy2"]`
|
||||
* where "proxy2" is the furthest down-stream and "proxy1" and
|
||||
* "proxy2" were trusted.
|
||||
*
|
||||
* @return {Array}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
req.__defineGetter__('ips', function(){
|
||||
var trust = this.app.get('trust proxy fn');
|
||||
var addrs = proxyaddr.all(this, trust);
|
||||
return addrs.slice(1).reverse();
|
||||
});
|
||||
|
||||
/**
|
||||
* Return subdomains as an array.
|
||||
*
|
||||
* Subdomains are the dot-separated parts of the host before the main domain of
|
||||
* the app. By default, the domain of the app is assumed to be the last two
|
||||
* parts of the host. This can be changed by setting "subdomain offset".
|
||||
*
|
||||
* For example, if the domain is "tobi.ferrets.example.com":
|
||||
* If "subdomain offset" is not set, req.subdomains is `["ferrets", "tobi"]`.
|
||||
* If "subdomain offset" is 3, req.subdomains is `["tobi"]`.
|
||||
*
|
||||
* @return {Array}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
req.__defineGetter__('subdomains', function(){
|
||||
var offset = this.app.get('subdomain offset');
|
||||
return (this.host || '')
|
||||
.split('.')
|
||||
.reverse()
|
||||
.slice(offset);
|
||||
});
|
||||
|
||||
/**
|
||||
* Short-hand for `url.parse(req.url).pathname`.
|
||||
*
|
||||
* @return {String}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
req.__defineGetter__('path', function(){
|
||||
return parse(this).pathname;
|
||||
});
|
||||
|
||||
/**
|
||||
* Parse the "Host" header field hostname.
|
||||
*
|
||||
* When the "trust proxy" setting trusts the socket
|
||||
* address, the "X-Forwarded-Host" header field will
|
||||
* be trusted.
|
||||
*
|
||||
* @return {String}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
req.__defineGetter__('host', function(){
|
||||
var trust = this.app.get('trust proxy fn');
|
||||
var host = this.get('X-Forwarded-Host');
|
||||
|
||||
if (!host || !trust(this.connection.remoteAddress)) {
|
||||
host = this.get('Host');
|
||||
}
|
||||
|
||||
if (!host) return;
|
||||
|
||||
// IPv6 literal support
|
||||
var offset = host[0] === '['
|
||||
? host.indexOf(']') + 1
|
||||
: 0;
|
||||
var index = host.indexOf(':', offset);
|
||||
|
||||
return ~index
|
||||
? host.substring(0, index)
|
||||
: host;
|
||||
});
|
||||
|
||||
/**
|
||||
* Check if the request is fresh, aka
|
||||
* Last-Modified and/or the ETag
|
||||
* still match.
|
||||
*
|
||||
* @return {Boolean}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
req.__defineGetter__('fresh', function(){
|
||||
var method = this.method;
|
||||
var s = this.res.statusCode;
|
||||
|
||||
// GET or HEAD for weak freshness validation only
|
||||
if ('GET' != method && 'HEAD' != method) return false;
|
||||
|
||||
// 2xx or 304 as per rfc2616 14.26
|
||||
if ((s >= 200 && s < 300) || 304 == s) {
|
||||
return fresh(this.headers, this.res._headers);
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
/**
|
||||
* Check if the request is stale, aka
|
||||
* "Last-Modified" and / or the "ETag" for the
|
||||
* resource has changed.
|
||||
*
|
||||
* @return {Boolean}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
req.__defineGetter__('stale', function(){
|
||||
return !this.fresh;
|
||||
});
|
||||
|
||||
/**
|
||||
* Check if the request was an _XMLHttpRequest_.
|
||||
*
|
||||
* @return {Boolean}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
req.__defineGetter__('xhr', function(){
|
||||
var val = this.get('X-Requested-With') || '';
|
||||
return 'xmlhttprequest' == val.toLowerCase();
|
||||
});
|
|
@ -0,0 +1,783 @@
|
|||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var escapeHtml = require('escape-html');
|
||||
var http = require('http');
|
||||
var path = require('path');
|
||||
var mixin = require('utils-merge');
|
||||
var sign = require('cookie-signature').sign;
|
||||
var normalizeType = require('./utils').normalizeType;
|
||||
var normalizeTypes = require('./utils').normalizeTypes;
|
||||
var setCharset = require('./utils').setCharset;
|
||||
var contentDisposition = require('./utils').contentDisposition;
|
||||
var deprecate = require('./utils').deprecate;
|
||||
var statusCodes = http.STATUS_CODES;
|
||||
var cookie = require('cookie');
|
||||
var send = require('send');
|
||||
var basename = path.basename;
|
||||
var extname = path.extname;
|
||||
var mime = send.mime;
|
||||
var vary = require('vary');
|
||||
|
||||
/**
|
||||
* Response prototype.
|
||||
*/
|
||||
|
||||
var res = module.exports = {
|
||||
__proto__: http.ServerResponse.prototype
|
||||
};
|
||||
|
||||
/**
|
||||
* Set status `code`.
|
||||
*
|
||||
* @param {Number} code
|
||||
* @return {ServerResponse}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
res.status = function(code){
|
||||
this.statusCode = code;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set Link header field with the given `links`.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* res.links({
|
||||
* next: 'http://api.example.com/users?page=2',
|
||||
* last: 'http://api.example.com/users?page=5'
|
||||
* });
|
||||
*
|
||||
* @param {Object} links
|
||||
* @return {ServerResponse}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
res.links = function(links){
|
||||
var link = this.get('Link') || '';
|
||||
if (link) link += ', ';
|
||||
return this.set('Link', link + Object.keys(links).map(function(rel){
|
||||
return '<' + links[rel] + '>; rel="' + rel + '"';
|
||||
}).join(', '));
|
||||
};
|
||||
|
||||
/**
|
||||
* Send a response.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* res.send(new Buffer('wahoo'));
|
||||
* res.send({ some: 'json' });
|
||||
* res.send('<p>some html</p>');
|
||||
* res.send(404, 'Sorry, cant find that');
|
||||
* res.send(404);
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
res.send = function(body){
|
||||
var req = this.req;
|
||||
var head = 'HEAD' == req.method;
|
||||
var type;
|
||||
var encoding;
|
||||
var len;
|
||||
|
||||
// settings
|
||||
var app = this.app;
|
||||
|
||||
// allow status / body
|
||||
if (2 == arguments.length) {
|
||||
// res.send(body, status) backwards compat
|
||||
if ('number' != typeof body && 'number' == typeof arguments[1]) {
|
||||
this.statusCode = arguments[1];
|
||||
} else {
|
||||
this.statusCode = body;
|
||||
body = arguments[1];
|
||||
}
|
||||
}
|
||||
|
||||
switch (typeof body) {
|
||||
// response status
|
||||
case 'number':
|
||||
this.get('Content-Type') || this.type('txt');
|
||||
this.statusCode = body;
|
||||
body = http.STATUS_CODES[body];
|
||||
break;
|
||||
// string defaulting to html
|
||||
case 'string':
|
||||
if (!this.get('Content-Type')) this.type('html');
|
||||
break;
|
||||
case 'boolean':
|
||||
case 'object':
|
||||
if (null == body) {
|
||||
body = '';
|
||||
} else if (Buffer.isBuffer(body)) {
|
||||
this.get('Content-Type') || this.type('bin');
|
||||
} else {
|
||||
return this.json(body);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// write strings in utf-8
|
||||
if ('string' === typeof body) {
|
||||
encoding = 'utf8';
|
||||
type = this.get('Content-Type');
|
||||
|
||||
// reflect this in content-type
|
||||
if ('string' === typeof type) {
|
||||
this.set('Content-Type', setCharset(type, 'utf-8'));
|
||||
}
|
||||
}
|
||||
|
||||
// populate Content-Length
|
||||
if (undefined !== body && !this.get('Content-Length')) {
|
||||
len = Buffer.isBuffer(body)
|
||||
? body.length
|
||||
: Buffer.byteLength(body, encoding);
|
||||
this.set('Content-Length', len);
|
||||
}
|
||||
|
||||
// ETag support
|
||||
var etag = len !== undefined && app.get('etag fn');
|
||||
if (etag && ('GET' === req.method || 'HEAD' === req.method)) {
|
||||
if (!this.get('ETag')) {
|
||||
etag = etag(body, encoding);
|
||||
etag && this.set('ETag', etag);
|
||||
}
|
||||
}
|
||||
|
||||
// freshness
|
||||
if (req.fresh) this.statusCode = 304;
|
||||
|
||||
// strip irrelevant headers
|
||||
if (204 == this.statusCode || 304 == this.statusCode) {
|
||||
this.removeHeader('Content-Type');
|
||||
this.removeHeader('Content-Length');
|
||||
this.removeHeader('Transfer-Encoding');
|
||||
body = '';
|
||||
}
|
||||
|
||||
// respond
|
||||
this.end((head ? null : body), encoding);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Send JSON response.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* res.json(null);
|
||||
* res.json({ user: 'tj' });
|
||||
* res.json(500, 'oh noes!');
|
||||
* res.json(404, 'I dont have that');
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
res.json = function(obj){
|
||||
// allow status / body
|
||||
if (2 == arguments.length) {
|
||||
// res.json(body, status) backwards compat
|
||||
if ('number' == typeof arguments[1]) {
|
||||
this.statusCode = arguments[1];
|
||||
return 'number' === typeof obj
|
||||
? jsonNumDeprecated.call(this, obj)
|
||||
: jsonDeprecated.call(this, obj);
|
||||
} else {
|
||||
this.statusCode = obj;
|
||||
obj = arguments[1];
|
||||
}
|
||||
}
|
||||
|
||||
// settings
|
||||
var app = this.app;
|
||||
var replacer = app.get('json replacer');
|
||||
var spaces = app.get('json spaces');
|
||||
var body = JSON.stringify(obj, replacer, spaces);
|
||||
|
||||
// content-type
|
||||
this.get('Content-Type') || this.set('Content-Type', 'application/json');
|
||||
|
||||
return this.send(body);
|
||||
};
|
||||
|
||||
var jsonDeprecated = deprecate(res.json,
|
||||
'res.json(obj, status): Use res.json(status, obj) instead');
|
||||
|
||||
var jsonNumDeprecated = deprecate(res.json,
|
||||
'res.json(num, status): Use res.status(status).json(num) instead');
|
||||
|
||||
/**
|
||||
* Send JSON response with JSONP callback support.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* res.jsonp(null);
|
||||
* res.jsonp({ user: 'tj' });
|
||||
* res.jsonp(500, 'oh noes!');
|
||||
* res.jsonp(404, 'I dont have that');
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
res.jsonp = function(obj){
|
||||
// allow status / body
|
||||
if (2 == arguments.length) {
|
||||
// res.json(body, status) backwards compat
|
||||
if ('number' == typeof arguments[1]) {
|
||||
this.statusCode = arguments[1];
|
||||
return 'number' === typeof obj
|
||||
? jsonpNumDeprecated.call(this, obj)
|
||||
: jsonpDeprecated.call(this, obj);
|
||||
} else {
|
||||
this.statusCode = obj;
|
||||
obj = arguments[1];
|
||||
}
|
||||
}
|
||||
|
||||
// settings
|
||||
var app = this.app;
|
||||
var replacer = app.get('json replacer');
|
||||
var spaces = app.get('json spaces');
|
||||
var body = JSON.stringify(obj, replacer, spaces)
|
||||
.replace(/\u2028/g, '\\u2028')
|
||||
.replace(/\u2029/g, '\\u2029');
|
||||
var callback = this.req.query[app.get('jsonp callback name')];
|
||||
|
||||
// content-type
|
||||
this.get('Content-Type') || this.set('Content-Type', 'application/json');
|
||||
|
||||
// fixup callback
|
||||
if (Array.isArray(callback)) {
|
||||
callback = callback[0];
|
||||
}
|
||||
|
||||
// jsonp
|
||||
if (callback && 'string' === typeof callback) {
|
||||
this.set('Content-Type', 'text/javascript');
|
||||
var cb = callback.replace(/[^\[\]\w$.]/g, '');
|
||||
body = 'typeof ' + cb + ' === \'function\' && ' + cb + '(' + body + ');';
|
||||
}
|
||||
|
||||
return this.send(body);
|
||||
};
|
||||
|
||||
var jsonpDeprecated = deprecate(res.json,
|
||||
'res.jsonp(obj, status): Use res.jsonp(status, obj) instead');
|
||||
|
||||
var jsonpNumDeprecated = deprecate(res.json,
|
||||
'res.jsonp(num, status): Use res.status(status).jsonp(num) instead');
|
||||
|
||||
/**
|
||||
* Transfer the file at the given `path`.
|
||||
*
|
||||
* Automatically sets the _Content-Type_ response header field.
|
||||
* The callback `fn(err)` is invoked when the transfer is complete
|
||||
* or when an error occurs. Be sure to check `res.sentHeader`
|
||||
* if you wish to attempt responding, as the header and some data
|
||||
* may have already been transferred.
|
||||
*
|
||||
* Options:
|
||||
*
|
||||
* - `maxAge` defaulting to 0
|
||||
* - `root` root directory for relative filenames
|
||||
* - `hidden` serve hidden files, defaulting to false
|
||||
*
|
||||
* Other options are passed along to `send`.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* The following example illustrates how `res.sendfile()` may
|
||||
* be used as an alternative for the `static()` middleware for
|
||||
* dynamic situations. The code backing `res.sendfile()` is actually
|
||||
* the same code, so HTTP cache support etc is identical.
|
||||
*
|
||||
* app.get('/user/:uid/photos/:file', function(req, res){
|
||||
* var uid = req.params.uid
|
||||
* , file = req.params.file;
|
||||
*
|
||||
* req.user.mayViewFilesFrom(uid, function(yes){
|
||||
* if (yes) {
|
||||
* res.sendfile('/uploads/' + uid + '/' + file);
|
||||
* } else {
|
||||
* res.send(403, 'Sorry! you cant see that.');
|
||||
* }
|
||||
* });
|
||||
* });
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
res.sendfile = function(path, options, fn){
|
||||
options = options || {};
|
||||
var self = this;
|
||||
var req = self.req;
|
||||
var next = this.req.next;
|
||||
var done;
|
||||
|
||||
|
||||
// support function as second arg
|
||||
if ('function' == typeof options) {
|
||||
fn = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
// socket errors
|
||||
req.socket.on('error', error);
|
||||
|
||||
// errors
|
||||
function error(err) {
|
||||
if (done) return;
|
||||
done = true;
|
||||
|
||||
// clean up
|
||||
cleanup();
|
||||
if (!self.headersSent) self.removeHeader('Content-Disposition');
|
||||
|
||||
// callback available
|
||||
if (fn) return fn(err);
|
||||
|
||||
// list in limbo if there's no callback
|
||||
if (self.headersSent) return;
|
||||
|
||||
// delegate
|
||||
next(err);
|
||||
}
|
||||
|
||||
// streaming
|
||||
function stream(stream) {
|
||||
if (done) return;
|
||||
cleanup();
|
||||
if (fn) stream.on('end', fn);
|
||||
}
|
||||
|
||||
// cleanup
|
||||
function cleanup() {
|
||||
req.socket.removeListener('error', error);
|
||||
}
|
||||
|
||||
// Back-compat
|
||||
options.maxage = options.maxage || options.maxAge || 0;
|
||||
|
||||
// transfer
|
||||
var file = send(req, path, options);
|
||||
file.on('error', error);
|
||||
file.on('directory', next);
|
||||
file.on('stream', stream);
|
||||
file.pipe(this);
|
||||
this.on('finish', cleanup);
|
||||
};
|
||||
|
||||
/**
|
||||
* Transfer the file at the given `path` as an attachment.
|
||||
*
|
||||
* Optionally providing an alternate attachment `filename`,
|
||||
* and optional callback `fn(err)`. The callback is invoked
|
||||
* when the data transfer is complete, or when an error has
|
||||
* ocurred. Be sure to check `res.headersSent` if you plan to respond.
|
||||
*
|
||||
* This method uses `res.sendfile()`.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
res.download = function(path, filename, fn){
|
||||
// support function as second arg
|
||||
if ('function' == typeof filename) {
|
||||
fn = filename;
|
||||
filename = null;
|
||||
}
|
||||
|
||||
filename = filename || path;
|
||||
this.set('Content-Disposition', contentDisposition(filename));
|
||||
return this.sendfile(path, fn);
|
||||
};
|
||||
|
||||
/**
|
||||
* Set _Content-Type_ response header with `type` through `mime.lookup()`
|
||||
* when it does not contain "/", or set the Content-Type to `type` otherwise.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* res.type('.html');
|
||||
* res.type('html');
|
||||
* res.type('json');
|
||||
* res.type('application/json');
|
||||
* res.type('png');
|
||||
*
|
||||
* @param {String} type
|
||||
* @return {ServerResponse} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
res.contentType =
|
||||
res.type = function(type){
|
||||
return this.set('Content-Type', ~type.indexOf('/')
|
||||
? type
|
||||
: mime.lookup(type));
|
||||
};
|
||||
|
||||
/**
|
||||
* Respond to the Acceptable formats using an `obj`
|
||||
* of mime-type callbacks.
|
||||
*
|
||||
* This method uses `req.accepted`, an array of
|
||||
* acceptable types ordered by their quality values.
|
||||
* When "Accept" is not present the _first_ callback
|
||||
* is invoked, otherwise the first match is used. When
|
||||
* no match is performed the server responds with
|
||||
* 406 "Not Acceptable".
|
||||
*
|
||||
* Content-Type is set for you, however if you choose
|
||||
* you may alter this within the callback using `res.type()`
|
||||
* or `res.set('Content-Type', ...)`.
|
||||
*
|
||||
* res.format({
|
||||
* 'text/plain': function(){
|
||||
* res.send('hey');
|
||||
* },
|
||||
*
|
||||
* 'text/html': function(){
|
||||
* res.send('<p>hey</p>');
|
||||
* },
|
||||
*
|
||||
* 'appliation/json': function(){
|
||||
* res.send({ message: 'hey' });
|
||||
* }
|
||||
* });
|
||||
*
|
||||
* In addition to canonicalized MIME types you may
|
||||
* also use extnames mapped to these types:
|
||||
*
|
||||
* res.format({
|
||||
* text: function(){
|
||||
* res.send('hey');
|
||||
* },
|
||||
*
|
||||
* html: function(){
|
||||
* res.send('<p>hey</p>');
|
||||
* },
|
||||
*
|
||||
* json: function(){
|
||||
* res.send({ message: 'hey' });
|
||||
* }
|
||||
* });
|
||||
*
|
||||
* By default Express passes an `Error`
|
||||
* with a `.status` of 406 to `next(err)`
|
||||
* if a match is not made. If you provide
|
||||
* a `.default` callback it will be invoked
|
||||
* instead.
|
||||
*
|
||||
* @param {Object} obj
|
||||
* @return {ServerResponse} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
res.format = function(obj){
|
||||
var req = this.req;
|
||||
var next = req.next;
|
||||
|
||||
var fn = obj.default;
|
||||
if (fn) delete obj.default;
|
||||
var keys = Object.keys(obj);
|
||||
|
||||
var key = req.accepts(keys);
|
||||
|
||||
this.vary("Accept");
|
||||
|
||||
if (key) {
|
||||
this.set('Content-Type', normalizeType(key).value);
|
||||
obj[key](req, this, next);
|
||||
} else if (fn) {
|
||||
fn();
|
||||
} else {
|
||||
var err = new Error('Not Acceptable');
|
||||
err.status = 406;
|
||||
err.types = normalizeTypes(keys).map(function(o){ return o.value });
|
||||
next(err);
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set _Content-Disposition_ header to _attachment_ with optional `filename`.
|
||||
*
|
||||
* @param {String} filename
|
||||
* @return {ServerResponse}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
res.attachment = function(filename){
|
||||
if (filename) this.type(extname(filename));
|
||||
this.set('Content-Disposition', contentDisposition(filename));
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set header `field` to `val`, or pass
|
||||
* an object of header fields.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* res.set('Foo', ['bar', 'baz']);
|
||||
* res.set('Accept', 'application/json');
|
||||
* res.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' });
|
||||
*
|
||||
* Aliased as `res.header()`.
|
||||
*
|
||||
* @param {String|Object|Array} field
|
||||
* @param {String} val
|
||||
* @return {ServerResponse} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
res.set =
|
||||
res.header = function(field, val){
|
||||
if (2 == arguments.length) {
|
||||
if (Array.isArray(val)) val = val.map(String);
|
||||
else val = String(val);
|
||||
if ('content-type' == field.toLowerCase() && !/;\s*charset\s*=/.test(val)) {
|
||||
var charset = mime.charsets.lookup(val.split(';')[0]);
|
||||
if (charset) val += '; charset=' + charset.toLowerCase();
|
||||
}
|
||||
this.setHeader(field, val);
|
||||
} else {
|
||||
for (var key in field) {
|
||||
this.set(key, field[key]);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get value for header `field`.
|
||||
*
|
||||
* @param {String} field
|
||||
* @return {String}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
res.get = function(field){
|
||||
return this.getHeader(field);
|
||||
};
|
||||
|
||||
/**
|
||||
* Clear cookie `name`.
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {Object} options
|
||||
* @param {ServerResponse} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
res.clearCookie = function(name, options){
|
||||
var opts = { expires: new Date(1), path: '/' };
|
||||
return this.cookie(name, '', options
|
||||
? mixin(opts, options)
|
||||
: opts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Set cookie `name` to `val`, with the given `options`.
|
||||
*
|
||||
* Options:
|
||||
*
|
||||
* - `maxAge` max-age in milliseconds, converted to `expires`
|
||||
* - `signed` sign the cookie
|
||||
* - `path` defaults to "/"
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* // "Remember Me" for 15 minutes
|
||||
* res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });
|
||||
*
|
||||
* // save as above
|
||||
* res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {String|Object} val
|
||||
* @param {Options} options
|
||||
* @api public
|
||||
*/
|
||||
|
||||
res.cookie = function(name, val, options){
|
||||
options = mixin({}, options);
|
||||
var secret = this.req.secret;
|
||||
var signed = options.signed;
|
||||
if (signed && !secret) throw new Error('cookieParser("secret") required for signed cookies');
|
||||
if ('number' == typeof val) val = val.toString();
|
||||
if ('object' == typeof val) val = 'j:' + JSON.stringify(val);
|
||||
if (signed) val = 's:' + sign(val, secret);
|
||||
if ('maxAge' in options) {
|
||||
options.expires = new Date(Date.now() + options.maxAge);
|
||||
options.maxAge /= 1000;
|
||||
}
|
||||
if (null == options.path) options.path = '/';
|
||||
var headerVal = cookie.serialize(name, String(val), options);
|
||||
|
||||
// supports multiple 'res.cookie' calls by getting previous value
|
||||
var prev = this.get('Set-Cookie');
|
||||
if (prev) {
|
||||
if (Array.isArray(prev)) {
|
||||
headerVal = prev.concat(headerVal);
|
||||
} else {
|
||||
headerVal = [prev, headerVal];
|
||||
}
|
||||
}
|
||||
this.set('Set-Cookie', headerVal);
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the location header to `url`.
|
||||
*
|
||||
* The given `url` can also be "back", which redirects
|
||||
* to the _Referrer_ or _Referer_ headers or "/".
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* res.location('/foo/bar').;
|
||||
* res.location('http://example.com');
|
||||
* res.location('../login');
|
||||
*
|
||||
* @param {String} url
|
||||
* @api public
|
||||
*/
|
||||
|
||||
res.location = function(url){
|
||||
var req = this.req;
|
||||
|
||||
// "back" is an alias for the referrer
|
||||
if ('back' == url) url = req.get('Referrer') || '/';
|
||||
|
||||
// Respond
|
||||
this.set('Location', url);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Redirect to the given `url` with optional response `status`
|
||||
* defaulting to 302.
|
||||
*
|
||||
* The resulting `url` is determined by `res.location()`, so
|
||||
* it will play nicely with mounted apps, relative paths,
|
||||
* `"back"` etc.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* res.redirect('/foo/bar');
|
||||
* res.redirect('http://example.com');
|
||||
* res.redirect(301, 'http://example.com');
|
||||
* res.redirect('http://example.com', 301);
|
||||
* res.redirect('../login'); // /blog/post/1 -> /blog/login
|
||||
*
|
||||
* @param {String} url
|
||||
* @param {Number} code
|
||||
* @api public
|
||||
*/
|
||||
|
||||
res.redirect = function(url){
|
||||
var head = 'HEAD' == this.req.method;
|
||||
var status = 302;
|
||||
var body;
|
||||
|
||||
// allow status / url
|
||||
if (2 == arguments.length) {
|
||||
if ('number' == typeof url) {
|
||||
status = url;
|
||||
url = arguments[1];
|
||||
} else {
|
||||
status = arguments[1];
|
||||
}
|
||||
}
|
||||
|
||||
// Set location header
|
||||
this.location(url);
|
||||
url = this.get('Location');
|
||||
|
||||
// Support text/{plain,html} by default
|
||||
this.format({
|
||||
text: function(){
|
||||
body = statusCodes[status] + '. Redirecting to ' + encodeURI(url);
|
||||
},
|
||||
|
||||
html: function(){
|
||||
var u = escapeHtml(url);
|
||||
body = '<p>' + statusCodes[status] + '. Redirecting to <a href="' + u + '">' + u + '</a></p>';
|
||||
},
|
||||
|
||||
default: function(){
|
||||
body = '';
|
||||
}
|
||||
});
|
||||
|
||||
// Respond
|
||||
this.statusCode = status;
|
||||
this.set('Content-Length', Buffer.byteLength(body));
|
||||
this.end(head ? null : body);
|
||||
};
|
||||
|
||||
/**
|
||||
* Add `field` to Vary. If already present in the Vary set, then
|
||||
* this call is simply ignored.
|
||||
*
|
||||
* @param {Array|String} field
|
||||
* @param {ServerResponse} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
res.vary = function(field){
|
||||
// checks for back-compat
|
||||
if (!field) return this;
|
||||
if (Array.isArray(field) && !field.length) return this;
|
||||
|
||||
vary(this, field);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Render `view` with the given `options` and optional callback `fn`.
|
||||
* When a callback function is given a response will _not_ be made
|
||||
* automatically, otherwise a response of _200_ and _text/html_ is given.
|
||||
*
|
||||
* Options:
|
||||
*
|
||||
* - `cache` boolean hinting to the engine it should cache
|
||||
* - `filename` filename of the view being rendered
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
res.render = function(view, options, fn){
|
||||
options = options || {};
|
||||
var self = this;
|
||||
var req = this.req;
|
||||
var app = req.app;
|
||||
|
||||
// support callback function as second arg
|
||||
if ('function' == typeof options) {
|
||||
fn = options, options = {};
|
||||
}
|
||||
|
||||
// merge res.locals
|
||||
options._locals = self.locals;
|
||||
|
||||
// default callback to respond
|
||||
fn = fn || function(err, str){
|
||||
if (err) return req.next(err);
|
||||
self.send(str);
|
||||
};
|
||||
|
||||
// render
|
||||
app.render(view, options, fn);
|
||||
};
|
|
@ -0,0 +1,452 @@
|
|||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Route = require('./route');
|
||||
var Layer = require('./layer');
|
||||
var methods = require('methods');
|
||||
var debug = require('debug')('express:router');
|
||||
var parseUrl = require('parseurl');
|
||||
var slice = Array.prototype.slice;
|
||||
|
||||
/**
|
||||
* Initialize a new `Router` with the given `options`.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @return {Router} which is an callable function
|
||||
* @api public
|
||||
*/
|
||||
|
||||
var proto = module.exports = function(options) {
|
||||
options = options || {};
|
||||
|
||||
function router(req, res, next) {
|
||||
router.handle(req, res, next);
|
||||
}
|
||||
|
||||
// mixin Router class functions
|
||||
router.__proto__ = proto;
|
||||
|
||||
router.params = {};
|
||||
router._params = [];
|
||||
router.caseSensitive = options.caseSensitive;
|
||||
router.strict = options.strict;
|
||||
router.stack = [];
|
||||
|
||||
return router;
|
||||
};
|
||||
|
||||
/**
|
||||
* Map the given param placeholder `name`(s) to the given callback.
|
||||
*
|
||||
* Parameter mapping is used to provide pre-conditions to routes
|
||||
* which use normalized placeholders. For example a _:user_id_ parameter
|
||||
* could automatically load a user's information from the database without
|
||||
* any additional code,
|
||||
*
|
||||
* The callback uses the same signature as middleware, the only difference
|
||||
* being that the value of the placeholder is passed, in this case the _id_
|
||||
* of the user. Once the `next()` function is invoked, just like middleware
|
||||
* it will continue on to execute the route, or subsequent parameter functions.
|
||||
*
|
||||
* Just like in middleware, you must either respond to the request or call next
|
||||
* to avoid stalling the request.
|
||||
*
|
||||
* app.param('user_id', function(req, res, next, id){
|
||||
* User.find(id, function(err, user){
|
||||
* if (err) {
|
||||
* return next(err);
|
||||
* } else if (!user) {
|
||||
* return next(new Error('failed to load user'));
|
||||
* }
|
||||
* req.user = user;
|
||||
* next();
|
||||
* });
|
||||
* });
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {Function} fn
|
||||
* @return {app} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
proto.param = function(name, fn){
|
||||
// param logic
|
||||
if ('function' == typeof name) {
|
||||
this._params.push(name);
|
||||
return;
|
||||
}
|
||||
|
||||
// apply param functions
|
||||
var params = this._params;
|
||||
var len = params.length;
|
||||
var ret;
|
||||
|
||||
if (name[0] === ':') {
|
||||
name = name.substr(1);
|
||||
}
|
||||
|
||||
for (var i = 0; i < len; ++i) {
|
||||
if (ret = params[i](name, fn)) {
|
||||
fn = ret;
|
||||
}
|
||||
}
|
||||
|
||||
// ensure we end up with a
|
||||
// middleware function
|
||||
if ('function' != typeof fn) {
|
||||
throw new Error('invalid param() call for ' + name + ', got ' + fn);
|
||||
}
|
||||
|
||||
(this.params[name] = this.params[name] || []).push(fn);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Dispatch a req, res into the router.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
proto.handle = function(req, res, done) {
|
||||
var self = this;
|
||||
|
||||
debug('dispatching %s %s', req.method, req.url);
|
||||
|
||||
var method = req.method.toLowerCase();
|
||||
|
||||
var search = 1 + req.url.indexOf('?');
|
||||
var pathlength = search ? search - 1 : req.url.length;
|
||||
var fqdn = 1 + req.url.substr(0, pathlength).indexOf('://');
|
||||
var protohost = fqdn ? req.url.substr(0, req.url.indexOf('/', 2 + fqdn)) : '';
|
||||
var idx = 0;
|
||||
var removed = '';
|
||||
var slashAdded = false;
|
||||
var paramcalled = {};
|
||||
|
||||
// store options for OPTIONS request
|
||||
// only used if OPTIONS request
|
||||
var options = [];
|
||||
|
||||
// middleware and routes
|
||||
var stack = self.stack;
|
||||
|
||||
// manage inter-router variables
|
||||
var parent = req.next;
|
||||
var parentUrl = req.baseUrl || '';
|
||||
done = wrap(done, function(old, err) {
|
||||
req.baseUrl = parentUrl;
|
||||
req.next = parent;
|
||||
old(err);
|
||||
});
|
||||
req.next = next;
|
||||
|
||||
// for options requests, respond with a default if nothing else responds
|
||||
if (method === 'options') {
|
||||
done = wrap(done, function(old, err) {
|
||||
if (err || options.length === 0) return old(err);
|
||||
|
||||
var body = options.join(',');
|
||||
return res.set('Allow', body).send(body);
|
||||
});
|
||||
}
|
||||
|
||||
next();
|
||||
|
||||
function next(err) {
|
||||
if (err === 'route') {
|
||||
err = undefined;
|
||||
}
|
||||
|
||||
var layer = stack[idx++];
|
||||
var layerPath;
|
||||
|
||||
if (!layer) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
if (slashAdded) {
|
||||
req.url = req.url.substr(1);
|
||||
slashAdded = false;
|
||||
}
|
||||
|
||||
req.baseUrl = parentUrl;
|
||||
req.url = protohost + removed + req.url.substr(protohost.length);
|
||||
req.originalUrl = req.originalUrl || req.url;
|
||||
removed = '';
|
||||
|
||||
try {
|
||||
var path = parseUrl(req).pathname;
|
||||
if (undefined == path) path = '/';
|
||||
|
||||
if (!layer.match(path)) return next(err);
|
||||
|
||||
// route object and not middleware
|
||||
var route = layer.route;
|
||||
|
||||
// if final route, then we support options
|
||||
if (route) {
|
||||
// we don't run any routes with error first
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
req.route = route;
|
||||
|
||||
// we can now dispatch to the route
|
||||
if (method === 'options' && !route.methods['options']) {
|
||||
options.push.apply(options, route._options());
|
||||
}
|
||||
}
|
||||
|
||||
// Capture one-time layer values
|
||||
req.params = layer.params;
|
||||
layerPath = layer.path;
|
||||
|
||||
// this should be done for the layer
|
||||
return self.process_params(layer, paramcalled, req, res, function(err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (route) {
|
||||
return layer.handle(req, res, next);
|
||||
}
|
||||
|
||||
trim_prefix();
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
|
||||
function trim_prefix() {
|
||||
var c = path[layerPath.length];
|
||||
if (c && '/' != c && '.' != c) return next(err);
|
||||
|
||||
// Trim off the part of the url that matches the route
|
||||
// middleware (.use stuff) needs to have the path stripped
|
||||
removed = layerPath;
|
||||
if (removed.length) {
|
||||
debug('trim prefix (%s) from url %s', layerPath, req.url);
|
||||
req.url = protohost + req.url.substr(protohost.length + removed.length);
|
||||
}
|
||||
|
||||
// Ensure leading slash
|
||||
if (!fqdn && req.url[0] !== '/') {
|
||||
req.url = '/' + req.url;
|
||||
slashAdded = true;
|
||||
}
|
||||
|
||||
// Setup base URL (no trailing slash)
|
||||
if (removed.length && removed.substr(-1) === '/') {
|
||||
req.baseUrl = parentUrl + removed.substring(0, removed.length - 1);
|
||||
} else {
|
||||
req.baseUrl = parentUrl + removed;
|
||||
}
|
||||
|
||||
debug('%s %s : %s', layer.handle.name || 'anonymous', layerPath, req.originalUrl);
|
||||
var arity = layer.handle.length;
|
||||
try {
|
||||
if (err && arity === 4) {
|
||||
layer.handle(err, req, res, next);
|
||||
} else if (!err && arity < 4) {
|
||||
layer.handle(req, res, next);
|
||||
} else {
|
||||
next(err);
|
||||
}
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function wrap(old, fn) {
|
||||
return function () {
|
||||
var args = [old].concat(slice.call(arguments));
|
||||
fn.apply(this, args);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Process any parameters for the layer.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
proto.process_params = function(layer, called, req, res, done) {
|
||||
var params = this.params;
|
||||
|
||||
// captured parameters from the layer, keys and values
|
||||
var keys = layer.keys;
|
||||
|
||||
// fast track
|
||||
if (!keys || keys.length === 0) {
|
||||
return done();
|
||||
}
|
||||
|
||||
var i = 0;
|
||||
var name;
|
||||
var paramIndex = 0;
|
||||
var key;
|
||||
var paramVal;
|
||||
var paramCallbacks;
|
||||
var paramCalled;
|
||||
|
||||
// process params in order
|
||||
// param callbacks can be async
|
||||
function param(err) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
if (i >= keys.length ) {
|
||||
return done();
|
||||
}
|
||||
|
||||
paramIndex = 0;
|
||||
key = keys[i++];
|
||||
|
||||
if (!key) {
|
||||
return done();
|
||||
}
|
||||
|
||||
name = key.name;
|
||||
paramVal = req.params[name];
|
||||
paramCallbacks = params[name];
|
||||
paramCalled = called[name];
|
||||
|
||||
if (paramVal === undefined || !paramCallbacks) {
|
||||
return param();
|
||||
}
|
||||
|
||||
// param previously called with same value or error occurred
|
||||
if (paramCalled && (paramCalled.error || paramCalled.match === paramVal)) {
|
||||
// restore value
|
||||
req.params[name] = paramCalled.value;
|
||||
|
||||
// next param
|
||||
return param(paramCalled.error);
|
||||
}
|
||||
|
||||
called[name] = paramCalled = {
|
||||
error: null,
|
||||
match: paramVal,
|
||||
value: paramVal
|
||||
};
|
||||
|
||||
try {
|
||||
return paramCallback();
|
||||
} catch (err) {
|
||||
return done(err);
|
||||
}
|
||||
}
|
||||
|
||||
// single param callbacks
|
||||
function paramCallback(err) {
|
||||
var fn = paramCallbacks[paramIndex++];
|
||||
|
||||
// store updated value
|
||||
paramCalled.value = req.params[key.name];
|
||||
|
||||
if (err) {
|
||||
// store error
|
||||
paramCalled.error = err;
|
||||
param(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!fn) return param();
|
||||
|
||||
fn(req, res, paramCallback, paramVal, key.name);
|
||||
}
|
||||
|
||||
param();
|
||||
};
|
||||
|
||||
/**
|
||||
* Use the given middleware function, with optional path, defaulting to "/".
|
||||
*
|
||||
* Use (like `.all`) will run for any http METHOD, but it will not add
|
||||
* handlers for those methods so OPTIONS requests will not consider `.use`
|
||||
* functions even if they could respond.
|
||||
*
|
||||
* The other difference is that _route_ path is stripped and not visible
|
||||
* to the handler function. The main effect of this feature is that mounted
|
||||
* handlers can operate without any code changes regardless of the "prefix"
|
||||
* pathname.
|
||||
*
|
||||
* @param {String|Function} route
|
||||
* @param {Function} fn
|
||||
* @return {app} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
proto.use = function(route, fn){
|
||||
// default route to '/'
|
||||
if ('string' != typeof route) {
|
||||
fn = route;
|
||||
route = '/';
|
||||
}
|
||||
|
||||
if (typeof fn !== 'function') {
|
||||
var type = {}.toString.call(fn);
|
||||
var msg = 'Router.use() requires callback functions but got a ' + type;
|
||||
throw new Error(msg);
|
||||
}
|
||||
|
||||
// strip trailing slash
|
||||
if ('/' == route[route.length - 1]) {
|
||||
route = route.slice(0, -1);
|
||||
}
|
||||
|
||||
var layer = new Layer(route, {
|
||||
sensitive: this.caseSensitive,
|
||||
strict: this.strict,
|
||||
end: false
|
||||
}, fn);
|
||||
|
||||
// add the middleware
|
||||
debug('use %s %s', route || '/', fn.name || 'anonymous');
|
||||
|
||||
this.stack.push(layer);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new Route for the given path.
|
||||
*
|
||||
* Each route contains a separate middleware stack and VERB handlers.
|
||||
*
|
||||
* See the Route api documentation for details on adding handlers
|
||||
* and middleware to routes.
|
||||
*
|
||||
* @param {String} path
|
||||
* @return {Route}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
proto.route = function(path){
|
||||
var route = new Route(path);
|
||||
|
||||
var layer = new Layer(path, {
|
||||
sensitive: this.caseSensitive,
|
||||
strict: this.strict,
|
||||
end: true
|
||||
}, route.dispatch.bind(route));
|
||||
|
||||
layer.route = route;
|
||||
|
||||
this.stack.push(layer);
|
||||
return route;
|
||||
};
|
||||
|
||||
// create Router#VERB functions
|
||||
methods.concat('all').forEach(function(method){
|
||||
proto[method] = function(path){
|
||||
var route = this.route(path)
|
||||
route[method].apply(route, [].slice.call(arguments, 1));
|
||||
return this;
|
||||
};
|
||||
});
|
|
@ -0,0 +1,67 @@
|
|||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var pathRegexp = require('path-to-regexp');
|
||||
var debug = require('debug')('express:router:layer');
|
||||
|
||||
/**
|
||||
* Expose `Layer`.
|
||||
*/
|
||||
|
||||
module.exports = Layer;
|
||||
|
||||
function Layer(path, options, fn) {
|
||||
if (!(this instanceof Layer)) {
|
||||
return new Layer(path, options, fn);
|
||||
}
|
||||
|
||||
debug('new %s', path);
|
||||
options = options || {};
|
||||
this.regexp = pathRegexp(path, this.keys = [], options);
|
||||
this.handle = fn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this route matches `path`, if so
|
||||
* populate `.params`.
|
||||
*
|
||||
* @param {String} path
|
||||
* @return {Boolean}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Layer.prototype.match = function(path){
|
||||
var keys = this.keys;
|
||||
var params = this.params = {};
|
||||
var m = this.regexp.exec(path);
|
||||
var n = 0;
|
||||
var key;
|
||||
var val;
|
||||
|
||||
if (!m) return false;
|
||||
|
||||
this.path = m[0];
|
||||
|
||||
for (var i = 1, len = m.length; i < len; ++i) {
|
||||
key = keys[i - 1];
|
||||
|
||||
try {
|
||||
val = 'string' == typeof m[i]
|
||||
? decodeURIComponent(m[i])
|
||||
: m[i];
|
||||
} catch(e) {
|
||||
var err = new Error("Failed to decode param '" + m[i] + "'");
|
||||
err.status = 400;
|
||||
throw err;
|
||||
}
|
||||
|
||||
if (key) {
|
||||
params[key.name] = val;
|
||||
} else {
|
||||
params[n++] = val;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
|
@ -0,0 +1,191 @@
|
|||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var debug = require('debug')('express:router:route');
|
||||
var methods = require('methods');
|
||||
var utils = require('../utils');
|
||||
|
||||
/**
|
||||
* Expose `Route`.
|
||||
*/
|
||||
|
||||
module.exports = Route;
|
||||
|
||||
/**
|
||||
* Initialize `Route` with the given `path`,
|
||||
*
|
||||
* @param {String} path
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function Route(path) {
|
||||
debug('new %s', path);
|
||||
this.path = path;
|
||||
this.stack = undefined;
|
||||
|
||||
// route handlers for various http methods
|
||||
this.methods = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {Array} supported HTTP methods
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Route.prototype._options = function(){
|
||||
return Object.keys(this.methods).map(function(method) {
|
||||
return method.toUpperCase();
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* dispatch req, res into this route
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Route.prototype.dispatch = function(req, res, done){
|
||||
var self = this;
|
||||
var method = req.method.toLowerCase();
|
||||
|
||||
if (method === 'head' && !this.methods['head']) {
|
||||
method = 'get';
|
||||
}
|
||||
|
||||
req.route = self;
|
||||
|
||||
// single middleware route case
|
||||
if (typeof this.stack === 'function') {
|
||||
this.stack(req, res, done);
|
||||
return;
|
||||
}
|
||||
|
||||
var stack = self.stack;
|
||||
if (!stack) {
|
||||
return done();
|
||||
}
|
||||
|
||||
var idx = 0;
|
||||
(function next_layer(err) {
|
||||
if (err && err === 'route') {
|
||||
return done();
|
||||
}
|
||||
|
||||
var layer = stack[idx++];
|
||||
if (!layer) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
if (layer.method && layer.method !== method) {
|
||||
return next_layer(err);
|
||||
}
|
||||
|
||||
var arity = layer.handle.length;
|
||||
if (err) {
|
||||
if (arity < 4) {
|
||||
return next_layer(err);
|
||||
}
|
||||
|
||||
try {
|
||||
layer.handle(err, req, res, next_layer);
|
||||
} catch (err) {
|
||||
next_layer(err);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (arity > 3) {
|
||||
return next_layer();
|
||||
}
|
||||
|
||||
try {
|
||||
layer.handle(req, res, next_layer);
|
||||
} catch (err) {
|
||||
next_layer(err);
|
||||
}
|
||||
})();
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a handler for all HTTP verbs to this route.
|
||||
*
|
||||
* Behaves just like middleware and can respond or call `next`
|
||||
* to continue processing.
|
||||
*
|
||||
* You can use multiple `.all` call to add multiple handlers.
|
||||
*
|
||||
* function check_something(req, res, next){
|
||||
* next();
|
||||
* };
|
||||
*
|
||||
* function validate_user(req, res, next){
|
||||
* next();
|
||||
* };
|
||||
*
|
||||
* route
|
||||
* .all(validate_user)
|
||||
* .all(check_something)
|
||||
* .get(function(req, res, next){
|
||||
* res.send('hello world');
|
||||
* });
|
||||
*
|
||||
* @param {function} handler
|
||||
* @return {Route} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Route.prototype.all = function(){
|
||||
var self = this;
|
||||
var callbacks = utils.flatten([].slice.call(arguments));
|
||||
callbacks.forEach(function(fn) {
|
||||
if (typeof fn !== 'function') {
|
||||
var type = {}.toString.call(fn);
|
||||
var msg = 'Route.all() requires callback functions but got a ' + type;
|
||||
throw new Error(msg);
|
||||
}
|
||||
|
||||
if (!self.stack) {
|
||||
self.stack = fn;
|
||||
}
|
||||
else if (typeof self.stack === 'function') {
|
||||
self.stack = [{ handle: self.stack }, { handle: fn }];
|
||||
}
|
||||
else {
|
||||
self.stack.push({ handle: fn });
|
||||
}
|
||||
});
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
methods.forEach(function(method){
|
||||
Route.prototype[method] = function(){
|
||||
var self = this;
|
||||
var callbacks = utils.flatten([].slice.call(arguments));
|
||||
|
||||
callbacks.forEach(function(fn) {
|
||||
if (typeof fn !== 'function') {
|
||||
var type = {}.toString.call(fn);
|
||||
var msg = 'Route.' + method + '() requires callback functions but got a ' + type;
|
||||
throw new Error(msg);
|
||||
}
|
||||
|
||||
debug('%s %s', method, self.path);
|
||||
|
||||
if (!self.methods[method]) {
|
||||
self.methods[method] = true;
|
||||
}
|
||||
|
||||
if (!self.stack) {
|
||||
self.stack = [];
|
||||
}
|
||||
else if (typeof self.stack === 'function') {
|
||||
self.stack = [{ handle: self.stack }];
|
||||
}
|
||||
|
||||
self.stack.push({ method: method, handle: fn });
|
||||
});
|
||||
return self;
|
||||
};
|
||||
});
|
|
@ -0,0 +1,292 @@
|
|||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var mime = require('send').mime;
|
||||
var crc32 = require('buffer-crc32');
|
||||
var crypto = require('crypto');
|
||||
var basename = require('path').basename;
|
||||
var deprecate = require('util').deprecate;
|
||||
var proxyaddr = require('proxy-addr');
|
||||
|
||||
/**
|
||||
* Simple detection of charset parameter in content-type
|
||||
*/
|
||||
var charsetRegExp = /;\s*charset\s*=/;
|
||||
|
||||
/**
|
||||
* Deprecate function, like core `util.deprecate`,
|
||||
* but with NODE_ENV and color support.
|
||||
*
|
||||
* @param {Function} fn
|
||||
* @param {String} msg
|
||||
* @return {Function}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.deprecate = function(fn, msg){
|
||||
if (process.env.NODE_ENV === 'test') return fn;
|
||||
|
||||
// prepend module name
|
||||
msg = 'express: ' + msg;
|
||||
|
||||
if (process.stderr.isTTY) {
|
||||
// colorize
|
||||
msg = '\x1b[31;1m' + msg + '\x1b[0m';
|
||||
}
|
||||
|
||||
return deprecate(fn, msg);
|
||||
};
|
||||
|
||||
/**
|
||||
* Return strong ETag for `body`.
|
||||
*
|
||||
* @param {String|Buffer} body
|
||||
* @param {String} [encoding]
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.etag = function etag(body, encoding){
|
||||
if (body.length === 0) {
|
||||
// fast-path empty body
|
||||
return '"1B2M2Y8AsgTpgAmY7PhCfg=="'
|
||||
}
|
||||
|
||||
var hash = crypto
|
||||
.createHash('md5')
|
||||
.update(body, encoding)
|
||||
.digest('base64')
|
||||
return '"' + hash + '"'
|
||||
};
|
||||
|
||||
/**
|
||||
* Return weak ETag for `body`.
|
||||
*
|
||||
* @param {String|Buffer} body
|
||||
* @param {String} [encoding]
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.wetag = function wetag(body, encoding){
|
||||
if (body.length === 0) {
|
||||
// fast-path empty body
|
||||
return 'W/"0-0"'
|
||||
}
|
||||
|
||||
var buf = Buffer.isBuffer(body)
|
||||
? body
|
||||
: new Buffer(body, encoding)
|
||||
var len = buf.length
|
||||
return 'W/"' + len.toString(16) + '-' + crc32.unsigned(buf) + '"'
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if `path` looks absolute.
|
||||
*
|
||||
* @param {String} path
|
||||
* @return {Boolean}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.isAbsolute = function(path){
|
||||
if ('/' == path[0]) return true;
|
||||
if (':' == path[1] && '\\' == path[2]) return true;
|
||||
if ('\\\\' == path.substring(0, 2)) return true; // Microsoft Azure absolute path
|
||||
};
|
||||
|
||||
/**
|
||||
* Flatten the given `arr`.
|
||||
*
|
||||
* @param {Array} arr
|
||||
* @return {Array}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.flatten = function(arr, ret){
|
||||
ret = ret || [];
|
||||
var len = arr.length;
|
||||
for (var i = 0; i < len; ++i) {
|
||||
if (Array.isArray(arr[i])) {
|
||||
exports.flatten(arr[i], ret);
|
||||
} else {
|
||||
ret.push(arr[i]);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
/**
|
||||
* Normalize the given `type`, for example "html" becomes "text/html".
|
||||
*
|
||||
* @param {String} type
|
||||
* @return {Object}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.normalizeType = function(type){
|
||||
return ~type.indexOf('/')
|
||||
? acceptParams(type)
|
||||
: { value: mime.lookup(type), params: {} };
|
||||
};
|
||||
|
||||
/**
|
||||
* Normalize `types`, for example "html" becomes "text/html".
|
||||
*
|
||||
* @param {Array} types
|
||||
* @return {Array}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.normalizeTypes = function(types){
|
||||
var ret = [];
|
||||
|
||||
for (var i = 0; i < types.length; ++i) {
|
||||
ret.push(exports.normalizeType(types[i]));
|
||||
}
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
/**
|
||||
* Generate Content-Disposition header appropriate for the filename.
|
||||
* non-ascii filenames are urlencoded and a filename* parameter is added
|
||||
*
|
||||
* @param {String} filename
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.contentDisposition = function(filename){
|
||||
var ret = 'attachment';
|
||||
if (filename) {
|
||||
filename = basename(filename);
|
||||
// if filename contains non-ascii characters, add a utf-8 version ala RFC 5987
|
||||
ret = /[^\040-\176]/.test(filename)
|
||||
? 'attachment; filename="' + encodeURI(filename) + '"; filename*=UTF-8\'\'' + encodeURI(filename)
|
||||
: 'attachment; filename="' + filename + '"';
|
||||
}
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse accept params `str` returning an
|
||||
* object with `.value`, `.quality` and `.params`.
|
||||
* also includes `.originalIndex` for stable sorting
|
||||
*
|
||||
* @param {String} str
|
||||
* @return {Object}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function acceptParams(str, index) {
|
||||
var parts = str.split(/ *; */);
|
||||
var ret = { value: parts[0], quality: 1, params: {}, originalIndex: index };
|
||||
|
||||
for (var i = 1; i < parts.length; ++i) {
|
||||
var pms = parts[i].split(/ *= */);
|
||||
if ('q' == pms[0]) {
|
||||
ret.quality = parseFloat(pms[1]);
|
||||
} else {
|
||||
ret.params[pms[0]] = pms[1];
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile "etag" value to function.
|
||||
*
|
||||
* @param {Boolean|String|Function} val
|
||||
* @return {Function}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.compileETag = function(val) {
|
||||
var fn;
|
||||
|
||||
if (typeof val === 'function') {
|
||||
return val;
|
||||
}
|
||||
|
||||
switch (val) {
|
||||
case true:
|
||||
fn = exports.wetag;
|
||||
break;
|
||||
case false:
|
||||
break;
|
||||
case 'strong':
|
||||
fn = exports.etag;
|
||||
break;
|
||||
case 'weak':
|
||||
fn = exports.wetag;
|
||||
break;
|
||||
default:
|
||||
throw new TypeError('unknown value for etag function: ' + val);
|
||||
}
|
||||
|
||||
return fn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile "proxy trust" value to function.
|
||||
*
|
||||
* @param {Boolean|String|Number|Array|Function} val
|
||||
* @return {Function}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.compileTrust = function(val) {
|
||||
if (typeof val === 'function') return val;
|
||||
|
||||
if (val === true) {
|
||||
// Support plain true/false
|
||||
return function(){ return true };
|
||||
}
|
||||
|
||||
if (typeof val === 'number') {
|
||||
// Support trusting hop count
|
||||
return function(a, i){ return i < val };
|
||||
}
|
||||
|
||||
if (typeof val === 'string') {
|
||||
// Support comma-separated values
|
||||
val = val.split(/ *, */);
|
||||
}
|
||||
|
||||
return proxyaddr.compile(val || []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the charset in a given Content-Type string.
|
||||
*
|
||||
* @param {String} type
|
||||
* @param {String} charset
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.setCharset = function(type, charset){
|
||||
if (!type || !charset) return type;
|
||||
|
||||
var exists = charsetRegExp.test(type);
|
||||
|
||||
// removing existing charset
|
||||
if (exists) {
|
||||
var parts = type.split(';');
|
||||
|
||||
for (var i = 1; i < parts.length; i++) {
|
||||
if (charsetRegExp.test(';' + parts[i])) {
|
||||
parts.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
type = parts.join(';');
|
||||
}
|
||||
|
||||
return type + '; charset=' + charset;
|
||||
};
|
|
@ -0,0 +1,77 @@
|
|||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var utils = require('./utils');
|
||||
var dirname = path.dirname;
|
||||
var basename = path.basename;
|
||||
var extname = path.extname;
|
||||
var exists = fs.existsSync || path.existsSync;
|
||||
var join = path.join;
|
||||
|
||||
/**
|
||||
* Expose `View`.
|
||||
*/
|
||||
|
||||
module.exports = View;
|
||||
|
||||
/**
|
||||
* Initialize a new `View` with the given `name`.
|
||||
*
|
||||
* Options:
|
||||
*
|
||||
* - `defaultEngine` the default template engine name
|
||||
* - `engines` template engine require() cache
|
||||
* - `root` root path for view lookup
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {Object} options
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function View(name, options) {
|
||||
options = options || {};
|
||||
this.name = name;
|
||||
this.root = options.root;
|
||||
var engines = options.engines;
|
||||
this.defaultEngine = options.defaultEngine;
|
||||
var ext = this.ext = extname(name);
|
||||
if (!ext && !this.defaultEngine) throw new Error('No default engine was specified and no extension was provided.');
|
||||
if (!ext) name += (ext = this.ext = ('.' != this.defaultEngine[0] ? '.' : '') + this.defaultEngine);
|
||||
this.engine = engines[ext] || (engines[ext] = require(ext.slice(1)).__express);
|
||||
this.path = this.lookup(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup view by the given `path`
|
||||
*
|
||||
* @param {String} path
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
View.prototype.lookup = function(path){
|
||||
var ext = this.ext;
|
||||
|
||||
// <path>.<engine>
|
||||
if (!utils.isAbsolute(path)) path = join(this.root, path);
|
||||
if (exists(path)) return path;
|
||||
|
||||
// <path>/index.<engine>
|
||||
path = join(dirname(path), basename(path, ext), 'index' + ext);
|
||||
if (exists(path)) return path;
|
||||
};
|
||||
|
||||
/**
|
||||
* Render with the given `options` and callback `fn(err, str)`.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {Function} fn
|
||||
* @api private
|
||||
*/
|
||||
|
||||
View.prototype.render = function(options, fn){
|
||||
this.engine(this.path, options, fn);
|
||||
};
|
|
@ -0,0 +1,3 @@
|
|||
coverage/
|
||||
test/
|
||||
.travis.yml
|
|
@ -0,0 +1,38 @@
|
|||
|
||||
1.0.6 / 2014-06-24
|
||||
==================
|
||||
|
||||
* deps: negotiator@0.4.7
|
||||
|
||||
1.0.5 / 2014-06-20
|
||||
==================
|
||||
|
||||
* fix crash when unknown extension given
|
||||
|
||||
1.0.4 / 2014-06-19
|
||||
==================
|
||||
|
||||
* use `mime-types`
|
||||
|
||||
1.0.3 / 2014-06-11
|
||||
==================
|
||||
|
||||
* deps: negotiator@0.4.6
|
||||
- Order by specificity when quality is the same
|
||||
|
||||
1.0.2 / 2014-05-29
|
||||
==================
|
||||
|
||||
* Fix interpretation when header not in request
|
||||
* deps: pin negotiator@0.4.5
|
||||
|
||||
1.0.1 / 2014-01-18
|
||||
==================
|
||||
|
||||
* Identity encoding isn't always acceptable
|
||||
* deps: negotiator@~0.4.0
|
||||
|
||||
1.0.0 / 2013-12-27
|
||||
==================
|
||||
|
||||
* Genesis
|
|
@ -0,0 +1,101 @@
|
|||
# Accepts
|
||||
|
||||
[![NPM version](https://badge.fury.io/js/accepts.svg)](http://badge.fury.io/js/accepts)
|
||||
[![Build Status](https://travis-ci.org/expressjs/accepts.svg?branch=master)](https://travis-ci.org/expressjs/accepts)
|
||||
[![Coverage Status](https://img.shields.io/coveralls/expressjs/accepts.svg?branch=master)](https://coveralls.io/r/expressjs/accepts)
|
||||
|
||||
Higher level content negotation based on [negotiator](https://github.com/federomero/negotiator). Extracted from [koa](https://github.com/koajs/koa) for general use.
|
||||
|
||||
In addition to negotatior, it allows:
|
||||
|
||||
- Allows types as an array or arguments list, ie `(['text/html', 'application/json'])` as well as `('text/html', 'application/json')`.
|
||||
- Allows type shorthands such as `json`.
|
||||
- Returns `false` when no types match
|
||||
- Treats non-existent headers as `*`
|
||||
|
||||
## API
|
||||
|
||||
### var accept = new Accepts(req)
|
||||
|
||||
```js
|
||||
var accepts = require('accepts')
|
||||
|
||||
http.createServer(function (req, res) {
|
||||
var accept = accepts(req)
|
||||
})
|
||||
```
|
||||
|
||||
### accept\[property\]\(\)
|
||||
|
||||
Returns all the explicitly accepted content property as an array in descending priority.
|
||||
|
||||
- `accept.types()`
|
||||
- `accept.encodings()`
|
||||
- `accept.charsets()`
|
||||
- `accept.languages()`
|
||||
|
||||
They are also aliased in singular form such as `accept.type()`. `accept.languages()` is also aliased as `accept.langs()`, etc.
|
||||
|
||||
Note: you should almost never do this in a real app as it defeats the purpose of content negotiation.
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
// in Google Chrome
|
||||
var encodings = accept.encodings() // -> ['sdch', 'gzip', 'deflate']
|
||||
```
|
||||
|
||||
Since you probably don't support `sdch`, you should just supply the encodings you support:
|
||||
|
||||
```js
|
||||
var encoding = accept.encodings('gzip', 'deflate') // -> 'gzip', probably
|
||||
```
|
||||
|
||||
### accept\[property\]\(values, ...\)
|
||||
|
||||
You can either have `values` be an array or have an argument list of values.
|
||||
|
||||
If the client does not accept any `values`, `false` will be returned.
|
||||
If the client accepts any `values`, the preferred `value` will be return.
|
||||
|
||||
For `accept.types()`, shorthand mime types are allowed.
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
// req.headers.accept = 'application/json'
|
||||
|
||||
accept.types('json') // -> 'json'
|
||||
accept.types('html', 'json') // -> 'json'
|
||||
accept.types('html') // -> false
|
||||
|
||||
// req.headers.accept = ''
|
||||
// which is equivalent to `*`
|
||||
|
||||
accept.types() // -> [], no explicit types
|
||||
accept.types('text/html', 'text/json') // -> 'text/html', since it was first
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 Jonathan Ong me@jongleberry.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
|
@ -0,0 +1,160 @@
|
|||
var Negotiator = require('negotiator')
|
||||
var mime = require('mime-types')
|
||||
|
||||
var slice = [].slice
|
||||
|
||||
module.exports = Accepts
|
||||
|
||||
function Accepts(req) {
|
||||
if (!(this instanceof Accepts))
|
||||
return new Accepts(req)
|
||||
|
||||
this.headers = req.headers
|
||||
this.negotiator = Negotiator(req)
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given `type(s)` is acceptable, returning
|
||||
* the best match when true, otherwise `undefined`, in which
|
||||
* case you should respond with 406 "Not Acceptable".
|
||||
*
|
||||
* The `type` value may be a single mime type string
|
||||
* such as "application/json", the extension name
|
||||
* such as "json" or an array `["json", "html", "text/plain"]`. When a list
|
||||
* or array is given the _best_ match, if any is returned.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* // Accept: text/html
|
||||
* this.types('html');
|
||||
* // => "html"
|
||||
*
|
||||
* // Accept: text/*, application/json
|
||||
* this.types('html');
|
||||
* // => "html"
|
||||
* this.types('text/html');
|
||||
* // => "text/html"
|
||||
* this.types('json', 'text');
|
||||
* // => "json"
|
||||
* this.types('application/json');
|
||||
* // => "application/json"
|
||||
*
|
||||
* // Accept: text/*, application/json
|
||||
* this.types('image/png');
|
||||
* this.types('png');
|
||||
* // => undefined
|
||||
*
|
||||
* // Accept: text/*;q=.5, application/json
|
||||
* this.types(['html', 'json']);
|
||||
* this.types('html', 'json');
|
||||
* // => "json"
|
||||
*
|
||||
* @param {String|Array} type(s)...
|
||||
* @return {String|Array|Boolean}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Accepts.prototype.type =
|
||||
Accepts.prototype.types = function (types) {
|
||||
if (!Array.isArray(types)) types = slice.call(arguments);
|
||||
var n = this.negotiator;
|
||||
if (!types.length) return n.mediaTypes();
|
||||
if (!this.headers.accept) return types[0];
|
||||
var mimes = types.map(extToMime).filter(validMime);
|
||||
var accepts = n.mediaTypes(mimes);
|
||||
var first = accepts[0];
|
||||
if (!first) return false;
|
||||
return types[mimes.indexOf(first)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return accepted encodings or best fit based on `encodings`.
|
||||
*
|
||||
* Given `Accept-Encoding: gzip, deflate`
|
||||
* an array sorted by quality is returned:
|
||||
*
|
||||
* ['gzip', 'deflate']
|
||||
*
|
||||
* @param {String|Array} encoding(s)...
|
||||
* @return {String|Array}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Accepts.prototype.encoding =
|
||||
Accepts.prototype.encodings = function (encodings) {
|
||||
if (!Array.isArray(encodings)) encodings = slice.call(arguments);
|
||||
var n = this.negotiator;
|
||||
if (!encodings.length) return n.encodings();
|
||||
return n.encodings(encodings)[0] || false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return accepted charsets or best fit based on `charsets`.
|
||||
*
|
||||
* Given `Accept-Charset: utf-8, iso-8859-1;q=0.2, utf-7;q=0.5`
|
||||
* an array sorted by quality is returned:
|
||||
*
|
||||
* ['utf-8', 'utf-7', 'iso-8859-1']
|
||||
*
|
||||
* @param {String|Array} charset(s)...
|
||||
* @return {String|Array}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Accepts.prototype.charset =
|
||||
Accepts.prototype.charsets = function (charsets) {
|
||||
if (!Array.isArray(charsets)) charsets = [].slice.call(arguments);
|
||||
var n = this.negotiator;
|
||||
if (!charsets.length) return n.charsets();
|
||||
if (!this.headers['accept-charset']) return charsets[0];
|
||||
return n.charsets(charsets)[0] || false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return accepted languages or best fit based on `langs`.
|
||||
*
|
||||
* Given `Accept-Language: en;q=0.8, es, pt`
|
||||
* an array sorted by quality is returned:
|
||||
*
|
||||
* ['es', 'pt', 'en']
|
||||
*
|
||||
* @param {String|Array} lang(s)...
|
||||
* @return {Array|String}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Accepts.prototype.lang =
|
||||
Accepts.prototype.langs =
|
||||
Accepts.prototype.language =
|
||||
Accepts.prototype.languages = function (langs) {
|
||||
if (!Array.isArray(langs)) langs = slice.call(arguments);
|
||||
var n = this.negotiator;
|
||||
if (!langs.length) return n.languages();
|
||||
if (!this.headers['accept-language']) return langs[0];
|
||||
return n.languages(langs)[0] || false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert extnames to mime.
|
||||
*
|
||||
* @param {String} type
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function extToMime(type) {
|
||||
if (~type.indexOf('/')) return type;
|
||||
return mime.lookup(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if mime is valid.
|
||||
*
|
||||
* @param {String} type
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function validMime(type) {
|
||||
return typeof type === 'string';
|
||||
}
|
14
node_modules/express/node_modules/accepts/node_modules/mime-types/.npmignore
generated
vendored
100755
14
node_modules/express/node_modules/accepts/node_modules/mime-types/.npmignore
generated
vendored
100755
|
@ -0,0 +1,14 @@
|
|||
test
|
||||
build.js
|
||||
|
||||
# OS generated files #
|
||||
######################
|
||||
.DS_Store*
|
||||
# Icon?
|
||||
ehthumbs.db
|
||||
Thumbs.db
|
||||
|
||||
# Node.js #
|
||||
###########
|
||||
node_modules
|
||||
npm-debug.log
|
12
node_modules/express/node_modules/accepts/node_modules/mime-types/.travis.yml
generated
vendored
100755
12
node_modules/express/node_modules/accepts/node_modules/mime-types/.travis.yml
generated
vendored
100755
|
@ -0,0 +1,12 @@
|
|||
language: node_js
|
||||
node_js:
|
||||
- "0.8"
|
||||
- "0.10"
|
||||
- "0.11"
|
||||
matrix:
|
||||
allow_failures:
|
||||
- node_js: "0.11"
|
||||
fast_finish: true
|
||||
before_install:
|
||||
# remove build script deps before install
|
||||
- node -pe 'f="./package.json";p=require(f);d=p.devDependencies;for(k in d){if("co"===k.substr(0,2))delete d[k]}require("fs").writeFileSync(f,JSON.stringify(p,null,2))'
|
22
node_modules/express/node_modules/accepts/node_modules/mime-types/LICENSE
generated
vendored
100755
22
node_modules/express/node_modules/accepts/node_modules/mime-types/LICENSE
generated
vendored
100755
|
@ -0,0 +1,22 @@
|
|||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Jonathan Ong me@jongleberry.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
9
node_modules/express/node_modules/accepts/node_modules/mime-types/Makefile
generated
vendored
100755
9
node_modules/express/node_modules/accepts/node_modules/mime-types/Makefile
generated
vendored
100755
|
@ -0,0 +1,9 @@
|
|||
|
||||
build:
|
||||
node --harmony-generators build.js
|
||||
|
||||
test:
|
||||
node test/mime.js
|
||||
mocha --require should --reporter spec test/test.js
|
||||
|
||||
.PHONY: build test
|
101
node_modules/express/node_modules/accepts/node_modules/mime-types/README.md
generated
vendored
100755
101
node_modules/express/node_modules/accepts/node_modules/mime-types/README.md
generated
vendored
100755
|
@ -0,0 +1,101 @@
|
|||
# mime-types
|
||||
[![NPM version](https://badge.fury.io/js/mime-types.svg)](https://badge.fury.io/js/mime-types) [![Build Status](https://travis-ci.org/expressjs/mime-types.svg?branch=master)](https://travis-ci.org/expressjs/mime-types)
|
||||
|
||||
The ultimate javascript content-type utility.
|
||||
|
||||
### Install
|
||||
|
||||
```sh
|
||||
$ npm install mime-types
|
||||
```
|
||||
|
||||
#### Similar to [node-mime](https://github.com/broofa/node-mime), except:
|
||||
|
||||
- __No fallbacks.__ Instead of naively returning the first available type, `mime-types` simply returns `false`, so do `var type = mime.lookup('unrecognized') || 'application/octet-stream'`.
|
||||
- No `new Mime()` business, so you could do `var lookup = require('mime-types').lookup`.
|
||||
- Additional mime types are added such as jade and stylus. Feel free to add more!
|
||||
- Browser support via Browserify and Component by converting lists to JSON files.
|
||||
|
||||
Otherwise, the API is compatible.
|
||||
|
||||
### Adding Types
|
||||
|
||||
If you'd like to add additional types,
|
||||
simply create a PR adding the type to `custom.json` and
|
||||
a reference link to the [sources](SOURCES.md).
|
||||
|
||||
Do __NOT__ edit `mime.json` or `node.json`.
|
||||
Those are pulled using `build.js`.
|
||||
You should only touch `custom.json`.
|
||||
|
||||
## API
|
||||
|
||||
```js
|
||||
var mime = require('mime-types')
|
||||
```
|
||||
|
||||
All functions return `false` if input is invalid or not found.
|
||||
|
||||
### mime.lookup(path)
|
||||
|
||||
Lookup the content-type associated with a file.
|
||||
|
||||
```js
|
||||
mime.lookup('json') // 'application/json'
|
||||
mime.lookup('.md') // 'text/x-markdown'
|
||||
mime.lookup('file.html') // 'text/html'
|
||||
mime.lookup('folder/file.js') // 'application/javascript'
|
||||
|
||||
mime.lookup('cats') // false
|
||||
```
|
||||
|
||||
### mime.contentType(type)
|
||||
|
||||
Create a full content-type header given a content-type or extension.
|
||||
|
||||
```js
|
||||
mime.contentType('markdown') // 'text/x-markdown; charset=utf-8'
|
||||
mime.contentType('file.json') // 'application/json; charset=utf-8'
|
||||
```
|
||||
|
||||
### mime.extension(type)
|
||||
|
||||
Get the default extension for a content-type.
|
||||
|
||||
```js
|
||||
mime.extension('application/octet-stream') // 'bin'
|
||||
```
|
||||
|
||||
### mime.charset(type)
|
||||
|
||||
Lookup the implied default charset of a content-type.
|
||||
|
||||
```js
|
||||
mime.charset('text/x-markdown') // 'UTF-8'
|
||||
```
|
||||
|
||||
### mime.types[extension] = type
|
||||
|
||||
A map of content-types by extension.
|
||||
|
||||
### mime.extensions[type] = [extensions]
|
||||
|
||||
A map of extensions by content-type.
|
||||
|
||||
### mime.define(types)
|
||||
|
||||
Globally add definitions.
|
||||
`types` must be an object of the form:
|
||||
|
||||
```js
|
||||
{
|
||||
"<content-type>": [extensions...],
|
||||
"<content-type>": [extensions...]
|
||||
}
|
||||
```
|
||||
|
||||
See the `.json` files in `lib/` for examples.
|
||||
|
||||
## License
|
||||
|
||||
[MIT](LICENSE)
|
17
node_modules/express/node_modules/accepts/node_modules/mime-types/SOURCES.md
generated
vendored
100755
17
node_modules/express/node_modules/accepts/node_modules/mime-types/SOURCES.md
generated
vendored
100755
|
@ -0,0 +1,17 @@
|
|||
|
||||
### Sources for custom types
|
||||
|
||||
This is a list of sources for any custom mime types.
|
||||
When adding custom mime types, please link to where you found the mime type,
|
||||
even if it's from an unofficial source.
|
||||
|
||||
- `text/coffeescript` - http://coffeescript.org/#scripts
|
||||
- `text/x-handlebars-template` - https://handlebarsjs.com/#getting-started
|
||||
- `text/x-sass` & `text/x-scss` - https://github.com/janlelis/rubybuntu-mime/blob/master/sass.xml
|
||||
- `text.jsx` - http://facebook.github.io/react/docs/getting-started.html [[2]](https://github.com/facebook/react/blob/f230e0a03154e6f8a616e0da1fb3d97ffa1a6472/vendor/browser-transforms.js#L210)
|
||||
|
||||
[Sources for node.json types](https://github.com/broofa/node-mime/blob/master/types/node.types)
|
||||
|
||||
### Notes on weird types
|
||||
|
||||
- `font/opentype` - This type is technically invalid according to the spec. No valid types begin with `font/`. No-one uses the official type of `application/vnd.ms-opentype` as the community standardized `application/x-font-otf`. However, chrome logs nonsense warnings unless opentype fonts are served with `font/opentype`. [[1]](http://stackoverflow.com/questions/2871655/proper-mime-type-for-fonts)
|
16
node_modules/express/node_modules/accepts/node_modules/mime-types/component.json
generated
vendored
100755
16
node_modules/express/node_modules/accepts/node_modules/mime-types/component.json
generated
vendored
100755
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"name": "mime-types",
|
||||
"description": "The ultimate javascript content-type utility.",
|
||||
"version": "0.1.0",
|
||||
"author": {
|
||||
"name": "Jonathan Ong",
|
||||
"email": "me@jongleberry.com",
|
||||
"url": "http://jongleberry.com",
|
||||
"twitter": "https://twitter.com/jongleberry"
|
||||
},
|
||||
"repository": "expressjs/mime-types",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"scripts": ["lib/index.js"],
|
||||
"json": ["mime.json", "node.json", "custom.json"]
|
||||
}
|
27
node_modules/express/node_modules/accepts/node_modules/mime-types/lib/custom.json
generated
vendored
100755
27
node_modules/express/node_modules/accepts/node_modules/mime-types/lib/custom.json
generated
vendored
100755
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"text/jade": [
|
||||
"jade"
|
||||
],
|
||||
"text/stylus": [
|
||||
"stylus",
|
||||
"styl"
|
||||
],
|
||||
"text/less": [
|
||||
"less"
|
||||
],
|
||||
"text/x-sass": [
|
||||
"sass"
|
||||
],
|
||||
"text/x-scss": [
|
||||
"scss"
|
||||
],
|
||||
"text/coffeescript": [
|
||||
"coffee"
|
||||
],
|
||||
"text/x-handlebars-template": [
|
||||
"hbs"
|
||||
],
|
||||
"text/jsx": [
|
||||
"jsx"
|
||||
]
|
||||
}
|
74
node_modules/express/node_modules/accepts/node_modules/mime-types/lib/index.js
generated
vendored
100755
74
node_modules/express/node_modules/accepts/node_modules/mime-types/lib/index.js
generated
vendored
100755
|
@ -0,0 +1,74 @@
|
|||
|
||||
// types[extension] = type
|
||||
exports.types = Object.create(null)
|
||||
// extensions[type] = [extensions]
|
||||
exports.extensions = Object.create(null)
|
||||
// define more mime types
|
||||
exports.define = define
|
||||
|
||||
// store the json files
|
||||
exports.json = {
|
||||
mime: require('./mime.json'),
|
||||
node: require('./node.json'),
|
||||
custom: require('./custom.json'),
|
||||
}
|
||||
|
||||
exports.lookup = function (string) {
|
||||
if (!string || typeof string !== "string") return false
|
||||
string = string.replace(/.*[\.\/\\]/, '').toLowerCase()
|
||||
if (!string) return false
|
||||
return exports.types[string] || false
|
||||
}
|
||||
|
||||
exports.extension = function (type) {
|
||||
if (!type || typeof type !== "string") return false
|
||||
type = type.match(/^\s*([^;\s]*)(?:;|\s|$)/)
|
||||
if (!type) return false
|
||||
var exts = exports.extensions[type[1].toLowerCase()]
|
||||
if (!exts || !exts.length) return false
|
||||
return exts[0]
|
||||
}
|
||||
|
||||
// type has to be an exact mime type
|
||||
exports.charset = function (type) {
|
||||
// special cases
|
||||
switch (type) {
|
||||
case 'application/json': return 'UTF-8'
|
||||
}
|
||||
|
||||
// default text/* to utf-8
|
||||
if (/^text\//.test(type)) return 'UTF-8'
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// backwards compatibility
|
||||
exports.charsets = {
|
||||
lookup: exports.charset
|
||||
}
|
||||
|
||||
exports.contentType = function (type) {
|
||||
if (!type || typeof type !== "string") return false
|
||||
if (!~type.indexOf('/')) type = exports.lookup(type)
|
||||
if (!type) return false
|
||||
if (!~type.indexOf('charset')) {
|
||||
var charset = exports.charset(type)
|
||||
if (charset) type += '; charset=' + charset.toLowerCase()
|
||||
}
|
||||
return type
|
||||
}
|
||||
|
||||
define(exports.json.mime)
|
||||
define(exports.json.node)
|
||||
define(exports.json.custom)
|
||||
|
||||
function define(json) {
|
||||
Object.keys(json).forEach(function (type) {
|
||||
var exts = json[type] || []
|
||||
exports.extensions[type] = exports.extensions[type] || []
|
||||
exts.forEach(function (ext) {
|
||||
if (!~exports.extensions[type].indexOf(ext)) exports.extensions[type].push(ext)
|
||||
exports.types[ext] = type
|
||||
})
|
||||
})
|
||||
}
|
3317
node_modules/express/node_modules/accepts/node_modules/mime-types/lib/mime.json
generated
vendored
100755
3317
node_modules/express/node_modules/accepts/node_modules/mime-types/lib/mime.json
generated
vendored
100755
File diff suppressed because it is too large
Load Diff
55
node_modules/express/node_modules/accepts/node_modules/mime-types/lib/node.json
generated
vendored
100755
55
node_modules/express/node_modules/accepts/node_modules/mime-types/lib/node.json
generated
vendored
100755
|
@ -0,0 +1,55 @@
|
|||
{
|
||||
"text/vtt": [
|
||||
"vtt"
|
||||
],
|
||||
"application/x-chrome-extension": [
|
||||
"crx"
|
||||
],
|
||||
"text/x-component": [
|
||||
"htc"
|
||||
],
|
||||
"text/cache-manifest": [
|
||||
"manifest"
|
||||
],
|
||||
"application/octet-stream": [
|
||||
"buffer"
|
||||
],
|
||||
"application/mp4": [
|
||||
"m4p"
|
||||
],
|
||||
"audio/mp4": [
|
||||
"m4a"
|
||||
],
|
||||
"video/MP2T": [
|
||||
"ts"
|
||||
],
|
||||
"application/x-web-app-manifest+json": [
|
||||
"webapp"
|
||||
],
|
||||
"text/x-lua": [
|
||||
"lua"
|
||||
],
|
||||
"application/x-lua-bytecode": [
|
||||
"luac"
|
||||
],
|
||||
"text/x-markdown": [
|
||||
"markdown",
|
||||
"md",
|
||||
"mkd"
|
||||
],
|
||||
"text/plain": [
|
||||
"ini"
|
||||
],
|
||||
"application/dash+xml": [
|
||||
"mdp"
|
||||
],
|
||||
"font/opentype": [
|
||||
"otf"
|
||||
],
|
||||
"application/json": [
|
||||
"map"
|
||||
],
|
||||
"application/xml": [
|
||||
"xsd"
|
||||
]
|
||||
}
|
42
node_modules/express/node_modules/accepts/node_modules/mime-types/package.json
generated
vendored
100755
42
node_modules/express/node_modules/accepts/node_modules/mime-types/package.json
generated
vendored
100755
|
@ -0,0 +1,42 @@
|
|||
{
|
||||
"name": "mime-types",
|
||||
"description": "The ultimate javascript content-type utility.",
|
||||
"version": "1.0.1",
|
||||
"author": {
|
||||
"name": "Jonathan Ong",
|
||||
"email": "me@jongleberry.com",
|
||||
"url": "http://jongleberry.com"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Jeremiah Senkpiel",
|
||||
"email": "fishrock123@rocketmail.com",
|
||||
"url": "https://searchbeam.jit.su"
|
||||
}
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/expressjs/mime-types"
|
||||
},
|
||||
"license": "MIT",
|
||||
"main": "lib",
|
||||
"devDependencies": {
|
||||
"co": "3",
|
||||
"cogent": "0",
|
||||
"mocha": "1",
|
||||
"should": "3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "make test"
|
||||
},
|
||||
"readme": "# mime-types\n[![NPM version](https://badge.fury.io/js/mime-types.svg)](https://badge.fury.io/js/mime-types) [![Build Status](https://travis-ci.org/expressjs/mime-types.svg?branch=master)](https://travis-ci.org/expressjs/mime-types)\n\nThe ultimate javascript content-type utility.\n\n### Install\n\n```sh\n$ npm install mime-types\n```\n\n#### Similar to [node-mime](https://github.com/broofa/node-mime), except:\n\n- __No fallbacks.__ Instead of naively returning the first available type, `mime-types` simply returns `false`, so do `var type = mime.lookup('unrecognized') || 'application/octet-stream'`.\n- No `new Mime()` business, so you could do `var lookup = require('mime-types').lookup`.\n- Additional mime types are added such as jade and stylus. Feel free to add more!\n- Browser support via Browserify and Component by converting lists to JSON files.\n\nOtherwise, the API is compatible.\n\n### Adding Types\n\nIf you'd like to add additional types,\nsimply create a PR adding the type to `custom.json` and\na reference link to the [sources](SOURCES.md).\n\nDo __NOT__ edit `mime.json` or `node.json`.\nThose are pulled using `build.js`.\nYou should only touch `custom.json`.\n\n## API\n\n```js\nvar mime = require('mime-types')\n```\n\nAll functions return `false` if input is invalid or not found.\n\n### mime.lookup(path)\n\nLookup the content-type associated with a file.\n\n```js\nmime.lookup('json') // 'application/json'\nmime.lookup('.md') // 'text/x-markdown'\nmime.lookup('file.html') // 'text/html'\nmime.lookup('folder/file.js') // 'application/javascript'\n\nmime.lookup('cats') // false\n```\n\n### mime.contentType(type)\n\nCreate a full content-type header given a content-type or extension.\n\n```js\nmime.contentType('markdown') // 'text/x-markdown; charset=utf-8'\nmime.contentType('file.json') // 'application/json; charset=utf-8'\n```\n\n### mime.extension(type)\n\nGet the default extension for a content-type.\n\n```js\nmime.extension('application/octet-stream') // 'bin'\n```\n\n### mime.charset(type)\n\nLookup the implied default charset of a content-type.\n\n```js\nmime.charset('text/x-markdown') // 'UTF-8'\n```\n\n### mime.types[extension] = type\n\nA map of content-types by extension.\n\n### mime.extensions[type] = [extensions]\n\nA map of extensions by content-type.\n\n### mime.define(types)\n\nGlobally add definitions.\n`types` must be an object of the form:\n\n```js\n{\n \"<content-type>\": [extensions...],\n \"<content-type>\": [extensions...]\n}\n```\n\nSee the `.json` files in `lib/` for examples.\n\n## License\n\n[MIT](LICENSE)\n",
|
||||
"readmeFilename": "README.md",
|
||||
"bugs": {
|
||||
"url": "https://github.com/expressjs/mime-types/issues"
|
||||
},
|
||||
"_id": "mime-types@1.0.1",
|
||||
"_from": "mime-types@~1.0.0"
|
||||
}
|
3
node_modules/express/node_modules/accepts/node_modules/negotiator/.npmignore
generated
vendored
100755
3
node_modules/express/node_modules/accepts/node_modules/negotiator/.npmignore
generated
vendored
100755
|
@ -0,0 +1,3 @@
|
|||
examples
|
||||
test
|
||||
.travis.yml
|
27
node_modules/express/node_modules/accepts/node_modules/negotiator/LICENSE
generated
vendored
100755
27
node_modules/express/node_modules/accepts/node_modules/negotiator/LICENSE
generated
vendored
100755
|
@ -0,0 +1,27 @@
|
|||
Original "Negotiator" program Copyright Federico Romero
|
||||
Port to JavaScript Copyright Isaac Z. Schlueter
|
||||
|
||||
All rights reserved.
|
||||
|
||||
MIT License
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
90
node_modules/express/node_modules/accepts/node_modules/negotiator/lib/charset.js
generated
vendored
100755
90
node_modules/express/node_modules/accepts/node_modules/negotiator/lib/charset.js
generated
vendored
100755
|
@ -0,0 +1,90 @@
|
|||
module.exports = preferredCharsets;
|
||||
preferredCharsets.preferredCharsets = preferredCharsets;
|
||||
|
||||
function parseAcceptCharset(accept) {
|
||||
return accept.split(',').map(function(e) {
|
||||
return parseCharset(e.trim());
|
||||
}).filter(function(e) {
|
||||
return e;
|
||||
});
|
||||
}
|
||||
|
||||
function parseCharset(s) {
|
||||
var match = s.match(/^\s*(\S+?)\s*(?:;(.*))?$/);
|
||||
if (!match) return null;
|
||||
|
||||
var charset = match[1];
|
||||
var q = 1;
|
||||
if (match[2]) {
|
||||
var params = match[2].split(';')
|
||||
for (var i = 0; i < params.length; i ++) {
|
||||
var p = params[i].trim().split('=');
|
||||
if (p[0] === 'q') {
|
||||
q = parseFloat(p[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
charset: charset,
|
||||
q: q
|
||||
};
|
||||
}
|
||||
|
||||
function getCharsetPriority(charset, accepted) {
|
||||
return (accepted.map(function(a) {
|
||||
return specify(charset, a);
|
||||
}).filter(Boolean).sort(function (a, b) {
|
||||
if(a.s == b.s) {
|
||||
return a.q > b.q ? -1 : 1;
|
||||
} else {
|
||||
return a.s > b.s ? -1 : 1;
|
||||
}
|
||||
})[0] || {s: 0, q:0});
|
||||
}
|
||||
|
||||
function specify(charset, spec) {
|
||||
var s = 0;
|
||||
if(spec.charset === charset){
|
||||
s |= 1;
|
||||
} else if (spec.charset !== '*' ) {
|
||||
return null
|
||||
}
|
||||
|
||||
return {
|
||||
s: s,
|
||||
q: spec.q,
|
||||
}
|
||||
}
|
||||
|
||||
function preferredCharsets(accept, provided) {
|
||||
// RFC 2616 sec 14.2: no header = *
|
||||
accept = parseAcceptCharset(accept === undefined ? '*' : accept || '');
|
||||
if (provided) {
|
||||
return provided.map(function(type) {
|
||||
return [type, getCharsetPriority(type, accept)];
|
||||
}).filter(function(pair) {
|
||||
return pair[1].q > 0;
|
||||
}).sort(function(a, b) {
|
||||
var pa = a[1];
|
||||
var pb = b[1];
|
||||
if(pa.q == pb.q) {
|
||||
return pa.s < pb.s ? 1 : -1;
|
||||
} else {
|
||||
return pa.q < pb.q ? 1 : -1;
|
||||
}
|
||||
}).map(function(pair) {
|
||||
return pair[0];
|
||||
});
|
||||
} else {
|
||||
return accept.sort(function (a, b) {
|
||||
// revsort
|
||||
return a.q < b.q ? 1 : -1;
|
||||
}).filter(function(type) {
|
||||
return type.q > 0;
|
||||
}).map(function(type) {
|
||||
return type.charset;
|
||||
});
|
||||
}
|
||||
}
|
120
node_modules/express/node_modules/accepts/node_modules/negotiator/lib/encoding.js
generated
vendored
100755
120
node_modules/express/node_modules/accepts/node_modules/negotiator/lib/encoding.js
generated
vendored
100755
|
@ -0,0 +1,120 @@
|
|||
module.exports = preferredEncodings;
|
||||
preferredEncodings.preferredEncodings = preferredEncodings;
|
||||
|
||||
function parseAcceptEncoding(accept) {
|
||||
var acceptableEncodings;
|
||||
|
||||
if (accept) {
|
||||
acceptableEncodings = accept.split(',').map(function(e) {
|
||||
return parseEncoding(e.trim());
|
||||
});
|
||||
} else {
|
||||
acceptableEncodings = [];
|
||||
}
|
||||
|
||||
if (!acceptableEncodings.some(function(e) {
|
||||
return e && specify('identity', e);
|
||||
})) {
|
||||
/*
|
||||
* If identity doesn't explicitly appear in the accept-encoding header,
|
||||
* it's added to the list of acceptable encoding with the lowest q
|
||||
*
|
||||
*/
|
||||
var lowestQ = 1;
|
||||
|
||||
for(var i = 0; i < acceptableEncodings.length; i++){
|
||||
var e = acceptableEncodings[i];
|
||||
if(e && e.q < lowestQ){
|
||||
lowestQ = e.q;
|
||||
}
|
||||
}
|
||||
acceptableEncodings.push({
|
||||
encoding: 'identity',
|
||||
q: lowestQ / 2,
|
||||
});
|
||||
}
|
||||
|
||||
return acceptableEncodings.filter(function(e) {
|
||||
return e;
|
||||
});
|
||||
}
|
||||
|
||||
function parseEncoding(s) {
|
||||
var match = s.match(/^\s*(\S+?)\s*(?:;(.*))?$/);
|
||||
|
||||
if (!match) return null;
|
||||
|
||||
var encoding = match[1];
|
||||
var q = 1;
|
||||
if (match[2]) {
|
||||
var params = match[2].split(';');
|
||||
for (var i = 0; i < params.length; i ++) {
|
||||
var p = params[i].trim().split('=');
|
||||
if (p[0] === 'q') {
|
||||
q = parseFloat(p[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
encoding: encoding,
|
||||
q: q
|
||||
};
|
||||
}
|
||||
|
||||
function getEncodingPriority(encoding, accepted) {
|
||||
return (accepted.map(function(a) {
|
||||
return specify(encoding, a);
|
||||
}).filter(Boolean).sort(function (a, b) {
|
||||
if(a.s == b.s) {
|
||||
return a.q > b.q ? -1 : 1;
|
||||
} else {
|
||||
return a.s > b.s ? -1 : 1;
|
||||
}
|
||||
})[0] || {s: 0, q: 0});
|
||||
}
|
||||
|
||||
function specify(encoding, spec) {
|
||||
var s = 0;
|
||||
if(spec.encoding === encoding){
|
||||
s |= 1;
|
||||
} else if (spec.encoding !== '*' ) {
|
||||
return null
|
||||
}
|
||||
|
||||
return {
|
||||
s: s,
|
||||
q: spec.q,
|
||||
}
|
||||
};
|
||||
|
||||
function preferredEncodings(accept, provided) {
|
||||
accept = parseAcceptEncoding(accept || '');
|
||||
if (provided) {
|
||||
return provided.map(function(type) {
|
||||
return [type, getEncodingPriority(type, accept)];
|
||||
}).filter(function(pair) {
|
||||
return pair[1].q > 0;
|
||||
}).sort(function(a, b) {
|
||||
var pa = a[1];
|
||||
var pb = b[1];
|
||||
if(pa.q == pb.q) {
|
||||
return pa.s < pb.s ? 1 : -1;
|
||||
} else {
|
||||
return pa.q < pb.q ? 1 : -1;
|
||||
}
|
||||
}).map(function(pair) {
|
||||
return pair[0];
|
||||
});
|
||||
} else {
|
||||
return accept.sort(function (a, b) {
|
||||
// revsort
|
||||
return a.q < b.q ? 1 : -1;
|
||||
}).filter(function(type){
|
||||
return type.q > 0;
|
||||
}).map(function(type) {
|
||||
return type.encoding;
|
||||
});
|
||||
}
|
||||
}
|
103
node_modules/express/node_modules/accepts/node_modules/negotiator/lib/language.js
generated
vendored
100755
103
node_modules/express/node_modules/accepts/node_modules/negotiator/lib/language.js
generated
vendored
100755
|
@ -0,0 +1,103 @@
|
|||
module.exports = preferredLanguages;
|
||||
preferredLanguages.preferredLanguages = preferredLanguages;
|
||||
|
||||
function parseAcceptLanguage(accept) {
|
||||
return accept.split(',').map(function(e) {
|
||||
return parseLanguage(e.trim());
|
||||
}).filter(function(e) {
|
||||
return e;
|
||||
});
|
||||
}
|
||||
|
||||
function parseLanguage(s) {
|
||||
var match = s.match(/^\s*(\S+?)(?:-(\S+?))?\s*(?:;(.*))?$/);
|
||||
if (!match) return null;
|
||||
|
||||
var prefix = match[1],
|
||||
suffix = match[2],
|
||||
full = prefix;
|
||||
|
||||
if (suffix) full += "-" + suffix;
|
||||
|
||||
var q = 1;
|
||||
if (match[3]) {
|
||||
var params = match[3].split(';')
|
||||
for (var i = 0; i < params.length; i ++) {
|
||||
var p = params[i].split('=');
|
||||
if (p[0] === 'q') q = parseFloat(p[1]);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
prefix: prefix,
|
||||
suffix: suffix,
|
||||
q: q,
|
||||
full: full
|
||||
};
|
||||
}
|
||||
|
||||
function getLanguagePriority(language, accepted) {
|
||||
return (accepted.map(function(a){
|
||||
return specify(language, a);
|
||||
}).filter(Boolean).sort(function (a, b) {
|
||||
if(a.s == b.s) {
|
||||
return a.q > b.q ? -1 : 1;
|
||||
} else {
|
||||
return a.s > b.s ? -1 : 1;
|
||||
}
|
||||
})[0] || {s: 0, q: 0});
|
||||
}
|
||||
|
||||
function specify(language, spec) {
|
||||
var p = parseLanguage(language)
|
||||
if (!p) return null;
|
||||
var s = 0;
|
||||
if(spec.full === p.full){
|
||||
s |= 4;
|
||||
} else if (spec.prefix === p.full) {
|
||||
s |= 2;
|
||||
} else if (spec.full === p.prefix) {
|
||||
s |= 1;
|
||||
} else if (spec.full !== '*' ) {
|
||||
return null
|
||||
}
|
||||
|
||||
return {
|
||||
s: s,
|
||||
q: spec.q,
|
||||
}
|
||||
};
|
||||
|
||||
function preferredLanguages(accept, provided) {
|
||||
// RFC 2616 sec 14.4: no header = *
|
||||
accept = parseAcceptLanguage(accept === undefined ? '*' : accept || '');
|
||||
if (provided) {
|
||||
|
||||
var ret = provided.map(function(type) {
|
||||
return [type, getLanguagePriority(type, accept)];
|
||||
}).filter(function(pair) {
|
||||
return pair[1].q > 0;
|
||||
}).sort(function(a, b) {
|
||||
var pa = a[1];
|
||||
var pb = b[1];
|
||||
if(pa.q == pb.q) {
|
||||
return pa.s < pb.s ? 1 : -1;
|
||||
} else {
|
||||
return pa.q < pb.q ? 1 : -1;
|
||||
}
|
||||
}).map(function(pair) {
|
||||
return pair[0];
|
||||
});
|
||||
return ret;
|
||||
|
||||
} else {
|
||||
return accept.sort(function (a, b) {
|
||||
// revsort
|
||||
return a.q < b.q ? 1 : -1;
|
||||
}).filter(function(type) {
|
||||
return type.q > 0;
|
||||
}).map(function(type) {
|
||||
return type.full;
|
||||
});
|
||||
}
|
||||
}
|
125
node_modules/express/node_modules/accepts/node_modules/negotiator/lib/mediaType.js
generated
vendored
100755
125
node_modules/express/node_modules/accepts/node_modules/negotiator/lib/mediaType.js
generated
vendored
100755
|
@ -0,0 +1,125 @@
|
|||
module.exports = preferredMediaTypes;
|
||||
preferredMediaTypes.preferredMediaTypes = preferredMediaTypes;
|
||||
|
||||
function parseAccept(accept) {
|
||||
return accept.split(',').map(function(e) {
|
||||
return parseMediaType(e.trim());
|
||||
}).filter(function(e) {
|
||||
return e;
|
||||
});
|
||||
};
|
||||
|
||||
function parseMediaType(s) {
|
||||
var match = s.match(/\s*(\S+?)\/([^;\s]+)\s*(?:;(.*))?/);
|
||||
if (!match) return null;
|
||||
|
||||
var type = match[1],
|
||||
subtype = match[2],
|
||||
full = "" + type + "/" + subtype,
|
||||
params = {},
|
||||
q = 1;
|
||||
|
||||
if (match[3]) {
|
||||
params = match[3].split(';').map(function(s) {
|
||||
return s.trim().split('=');
|
||||
}).reduce(function (set, p) {
|
||||
set[p[0]] = p[1];
|
||||
return set
|
||||
}, params);
|
||||
|
||||
if (params.q != null) {
|
||||
q = parseFloat(params.q);
|
||||
delete params.q;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
type: type,
|
||||
subtype: subtype,
|
||||
params: params,
|
||||
q: q,
|
||||
full: full
|
||||
};
|
||||
}
|
||||
|
||||
function getMediaTypePriority(type, accepted) {
|
||||
return (accepted.map(function(a) {
|
||||
return specify(type, a);
|
||||
}).filter(Boolean).sort(function (a, b) {
|
||||
if(a.s == b.s) {
|
||||
return a.q > b.q ? -1 : 1;
|
||||
} else {
|
||||
return a.s > b.s ? -1 : 1;
|
||||
}
|
||||
})[0] || {s: 0, q: 0});
|
||||
}
|
||||
|
||||
function specify(type, spec) {
|
||||
var p = parseMediaType(type);
|
||||
var s = 0;
|
||||
|
||||
if (!p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(spec.type == p.type) {
|
||||
s |= 4
|
||||
} else if(spec.type != '*') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(spec.subtype == p.subtype) {
|
||||
s |= 2
|
||||
} else if(spec.subtype != '*') {
|
||||
return null;
|
||||
}
|
||||
|
||||
var keys = Object.keys(spec.params);
|
||||
if (keys.length > 0) {
|
||||
if (keys.every(function (k) {
|
||||
return spec.params[k] == '*' || spec.params[k] == p.params[k];
|
||||
})) {
|
||||
s |= 1
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
q: spec.q,
|
||||
s: s,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function preferredMediaTypes(accept, provided) {
|
||||
// RFC 2616 sec 14.2: no header = */*
|
||||
accept = parseAccept(accept === undefined ? '*/*' : accept || '');
|
||||
if (provided) {
|
||||
return provided.map(function(type) {
|
||||
return [type, getMediaTypePriority(type, accept)];
|
||||
}).filter(function(pair) {
|
||||
return pair[1].q > 0;
|
||||
}).sort(function(a, b) {
|
||||
var pa = a[1];
|
||||
var pb = b[1];
|
||||
if(pa.q == pb.q) {
|
||||
return pa.s < pb.s ? 1 : -1;
|
||||
} else {
|
||||
return pa.q < pb.q ? 1 : -1;
|
||||
}
|
||||
}).map(function(pair) {
|
||||
return pair[0];
|
||||
});
|
||||
|
||||
} else {
|
||||
return accept.sort(function (a, b) {
|
||||
// revsort
|
||||
return a.q < b.q ? 1 : -1;
|
||||
}).filter(function(type) {
|
||||
return type.q > 0;
|
||||
}).map(function(type) {
|
||||
return type.full;
|
||||
});
|
||||
}
|
||||
}
|
37
node_modules/express/node_modules/accepts/node_modules/negotiator/lib/negotiator.js
generated
vendored
100755
37
node_modules/express/node_modules/accepts/node_modules/negotiator/lib/negotiator.js
generated
vendored
100755
|
@ -0,0 +1,37 @@
|
|||
module.exports = Negotiator;
|
||||
Negotiator.Negotiator = Negotiator;
|
||||
|
||||
function Negotiator(request) {
|
||||
if (!(this instanceof Negotiator)) return new Negotiator(request);
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
var set = { charset: 'accept-charset',
|
||||
encoding: 'accept-encoding',
|
||||
language: 'accept-language',
|
||||
mediaType: 'accept' };
|
||||
|
||||
|
||||
function capitalize(string){
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
}
|
||||
|
||||
Object.keys(set).forEach(function (k) {
|
||||
var header = set[k],
|
||||
method = require('./'+k+'.js'),
|
||||
singular = k,
|
||||
plural = k + 's';
|
||||
|
||||
Negotiator.prototype[plural] = function (available) {
|
||||
return method(this.request.headers[header], available);
|
||||
};
|
||||
|
||||
Negotiator.prototype[singular] = function(available) {
|
||||
var set = this[plural](available);
|
||||
if (set) return set[0];
|
||||
};
|
||||
|
||||
// Keep preferred* methods for legacy compatibility
|
||||
Negotiator.prototype['preferred'+capitalize(plural)] = Negotiator.prototype[plural];
|
||||
Negotiator.prototype['preferred'+capitalize(singular)] = Negotiator.prototype[singular];
|
||||
})
|
49
node_modules/express/node_modules/accepts/node_modules/negotiator/package.json
generated
vendored
100755
49
node_modules/express/node_modules/accepts/node_modules/negotiator/package.json
generated
vendored
100755
|
@ -0,0 +1,49 @@
|
|||
{
|
||||
"name": "negotiator",
|
||||
"description": "HTTP content negotiation",
|
||||
"version": "0.4.7",
|
||||
"author": {
|
||||
"name": "Federico Romero",
|
||||
"email": "federico.romero@outboxlabs.com"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Isaac Z. Schlueter",
|
||||
"email": "i@izs.me",
|
||||
"url": "http://blog.izs.me/"
|
||||
}
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/federomero/negotiator.git"
|
||||
},
|
||||
"keywords": [
|
||||
"http",
|
||||
"content negotiation",
|
||||
"accept",
|
||||
"accept-language",
|
||||
"accept-encoding",
|
||||
"accept-charset"
|
||||
],
|
||||
"engine": "node >= 0.6",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"nodeunit": "0.8.x"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "nodeunit test"
|
||||
},
|
||||
"optionalDependencies": {},
|
||||
"engines": {
|
||||
"node": "*"
|
||||
},
|
||||
"main": "lib/negotiator.js",
|
||||
"readme": "# Negotiator [![Build Status](https://travis-ci.org/federomero/negotiator.png)](https://travis-ci.org/federomero/negotiator)\n\nAn HTTP content negotiator for node.js written in javascript.\n\n# Accept Negotiation\n\n Negotiator = require('negotiator')\n\n availableMediaTypes = ['text/html', 'text/plain', 'application/json']\n\n // The negotiator constructor receives a request object\n negotiator = new Negotiator(request)\n\n // Let's say Accept header is 'text/html, application/*;q=0.2, image/jpeg;q=0.8'\n\n negotiator.mediaTypes()\n // -> ['text/html', 'image/jpeg', 'application/*']\n\n negotiator.mediaTypes(availableMediaTypes)\n // -> ['text/html', 'application/json']\n\n negotiator.mediaType(availableMediaTypes)\n // -> 'text/html'\n\nYou can check a working example at `examples/accept.js`.\n\n## Methods\n\n`mediaTypes(availableMediaTypes)`:\n\nReturns an array of preferred media types ordered by priority from a list of available media types.\n\n`mediaType(availableMediaType)`:\n\nReturns the top preferred media type from a list of available media types.\n\n# Accept-Language Negotiation\n\n Negotiator = require('negotiator')\n\n negotiator = new Negotiator(request)\n\n availableLanguages = 'en', 'es', 'fr'\n\n // Let's say Accept-Language header is 'en;q=0.8, es, pt'\n\n negotiator.languages()\n // -> ['es', 'pt', 'en']\n\n negotiator.languages(availableLanguages)\n // -> ['es', 'en']\n\n language = negotiator.language(availableLanguages)\n // -> 'es'\n\nYou can check a working example at `examples/language.js`.\n\n## Methods\n\n`languages(availableLanguages)`:\n\nReturns an array of preferred languages ordered by priority from a list of available languages.\n\n`language(availableLanguages)`:\n\nReturns the top preferred language from a list of available languages.\n\n# Accept-Charset Negotiation\n\n Negotiator = require('negotiator')\n\n availableCharsets = ['utf-8', 'iso-8859-1', 'iso-8859-5']\n\n negotiator = new Negotiator(request)\n\n // Let's say Accept-Charset header is 'utf-8, iso-8859-1;q=0.8, utf-7;q=0.2'\n\n negotiator.charsets()\n // -> ['utf-8', 'iso-8859-1', 'utf-7']\n\n negotiator.charsets(availableCharsets)\n // -> ['utf-8', 'iso-8859-1']\n\n negotiator.charset(availableCharsets)\n // -> 'utf-8'\n\nYou can check a working example at `examples/charset.js`.\n\n## Methods\n\n`charsets(availableCharsets)`:\n\nReturns an array of preferred charsets ordered by priority from a list of available charsets.\n\n`charset(availableCharsets)`:\n\nReturns the top preferred charset from a list of available charsets.\n\n# Accept-Encoding Negotiation\n\n Negotiator = require('negotiator').Negotiator\n\n availableEncodings = ['identity', 'gzip']\n\n negotiator = new Negotiator(request)\n\n // Let's say Accept-Encoding header is 'gzip, compress;q=0.2, identity;q=0.5'\n\n negotiator.encodings()\n // -> ['gzip', 'identity', 'compress']\n\n negotiator.encodings(availableEncodings)\n // -> ['gzip', 'identity']\n\n negotiator.encoding(availableEncodings)\n // -> 'gzip'\n\nYou can check a working example at `examples/encoding.js`.\n\n## Methods\n\n`encodings(availableEncodings)`:\n\nReturns an array of preferred encodings ordered by priority from a list of available encodings.\n\n`encoding(availableEncodings)`:\n\nReturns the top preferred encoding from a list of available encodings.\n\n# License\n\nMIT\n",
|
||||
"readmeFilename": "readme.md",
|
||||
"bugs": {
|
||||
"url": "https://github.com/federomero/negotiator/issues"
|
||||
},
|
||||
"dependencies": {},
|
||||
"_id": "negotiator@0.4.7",
|
||||
"_from": "negotiator@0.4.7"
|
||||
}
|
132
node_modules/express/node_modules/accepts/node_modules/negotiator/readme.md
generated
vendored
100755
132
node_modules/express/node_modules/accepts/node_modules/negotiator/readme.md
generated
vendored
100755
|
@ -0,0 +1,132 @@
|
|||
# Negotiator [![Build Status](https://travis-ci.org/federomero/negotiator.png)](https://travis-ci.org/federomero/negotiator)
|
||||
|
||||
An HTTP content negotiator for node.js written in javascript.
|
||||
|
||||
# Accept Negotiation
|
||||
|
||||
Negotiator = require('negotiator')
|
||||
|
||||
availableMediaTypes = ['text/html', 'text/plain', 'application/json']
|
||||
|
||||
// The negotiator constructor receives a request object
|
||||
negotiator = new Negotiator(request)
|
||||
|
||||
// Let's say Accept header is 'text/html, application/*;q=0.2, image/jpeg;q=0.8'
|
||||
|
||||
negotiator.mediaTypes()
|
||||
// -> ['text/html', 'image/jpeg', 'application/*']
|
||||
|
||||
negotiator.mediaTypes(availableMediaTypes)
|
||||
// -> ['text/html', 'application/json']
|
||||
|
||||
negotiator.mediaType(availableMediaTypes)
|
||||
// -> 'text/html'
|
||||
|
||||
You can check a working example at `examples/accept.js`.
|
||||
|
||||
## Methods
|
||||
|
||||
`mediaTypes(availableMediaTypes)`:
|
||||
|
||||
Returns an array of preferred media types ordered by priority from a list of available media types.
|
||||
|
||||
`mediaType(availableMediaType)`:
|
||||
|
||||
Returns the top preferred media type from a list of available media types.
|
||||
|
||||
# Accept-Language Negotiation
|
||||
|
||||
Negotiator = require('negotiator')
|
||||
|
||||
negotiator = new Negotiator(request)
|
||||
|
||||
availableLanguages = 'en', 'es', 'fr'
|
||||
|
||||
// Let's say Accept-Language header is 'en;q=0.8, es, pt'
|
||||
|
||||
negotiator.languages()
|
||||
// -> ['es', 'pt', 'en']
|
||||
|
||||
negotiator.languages(availableLanguages)
|
||||
// -> ['es', 'en']
|
||||
|
||||
language = negotiator.language(availableLanguages)
|
||||
// -> 'es'
|
||||
|
||||
You can check a working example at `examples/language.js`.
|
||||
|
||||
## Methods
|
||||
|
||||
`languages(availableLanguages)`:
|
||||
|
||||
Returns an array of preferred languages ordered by priority from a list of available languages.
|
||||
|
||||
`language(availableLanguages)`:
|
||||
|
||||
Returns the top preferred language from a list of available languages.
|
||||
|
||||
# Accept-Charset Negotiation
|
||||
|
||||
Negotiator = require('negotiator')
|
||||
|
||||
availableCharsets = ['utf-8', 'iso-8859-1', 'iso-8859-5']
|
||||
|
||||
negotiator = new Negotiator(request)
|
||||
|
||||
// Let's say Accept-Charset header is 'utf-8, iso-8859-1;q=0.8, utf-7;q=0.2'
|
||||
|
||||
negotiator.charsets()
|
||||
// -> ['utf-8', 'iso-8859-1', 'utf-7']
|
||||
|
||||
negotiator.charsets(availableCharsets)
|
||||
// -> ['utf-8', 'iso-8859-1']
|
||||
|
||||
negotiator.charset(availableCharsets)
|
||||
// -> 'utf-8'
|
||||
|
||||
You can check a working example at `examples/charset.js`.
|
||||
|
||||
## Methods
|
||||
|
||||
`charsets(availableCharsets)`:
|
||||
|
||||
Returns an array of preferred charsets ordered by priority from a list of available charsets.
|
||||
|
||||
`charset(availableCharsets)`:
|
||||
|
||||
Returns the top preferred charset from a list of available charsets.
|
||||
|
||||
# Accept-Encoding Negotiation
|
||||
|
||||
Negotiator = require('negotiator').Negotiator
|
||||
|
||||
availableEncodings = ['identity', 'gzip']
|
||||
|
||||
negotiator = new Negotiator(request)
|
||||
|
||||
// Let's say Accept-Encoding header is 'gzip, compress;q=0.2, identity;q=0.5'
|
||||
|
||||
negotiator.encodings()
|
||||
// -> ['gzip', 'identity', 'compress']
|
||||
|
||||
negotiator.encodings(availableEncodings)
|
||||
// -> ['gzip', 'identity']
|
||||
|
||||
negotiator.encoding(availableEncodings)
|
||||
// -> 'gzip'
|
||||
|
||||
You can check a working example at `examples/encoding.js`.
|
||||
|
||||
## Methods
|
||||
|
||||
`encodings(availableEncodings)`:
|
||||
|
||||
Returns an array of preferred encodings ordered by priority from a list of available encodings.
|
||||
|
||||
`encoding(availableEncodings)`:
|
||||
|
||||
Returns the top preferred encoding from a list of available encodings.
|
||||
|
||||
# License
|
||||
|
||||
MIT
|
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
"name": "accepts",
|
||||
"description": "Higher-level content negotiation",
|
||||
"version": "1.0.6",
|
||||
"author": {
|
||||
"name": "Jonathan Ong",
|
||||
"email": "me@jongleberry.com",
|
||||
"url": "http://jongleberry.com"
|
||||
},
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/expressjs/accepts"
|
||||
},
|
||||
"dependencies": {
|
||||
"mime-types": "~1.0.0",
|
||||
"negotiator": "0.4.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"istanbul": "0.2.11",
|
||||
"mocha": "*",
|
||||
"should": "*"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha --require should --reporter dot test/",
|
||||
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --require should --reporter dot test/",
|
||||
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --require should --reporter spec test/"
|
||||
},
|
||||
"readme": "# Accepts\n\n[![NPM version](https://badge.fury.io/js/accepts.svg)](http://badge.fury.io/js/accepts)\n[![Build Status](https://travis-ci.org/expressjs/accepts.svg?branch=master)](https://travis-ci.org/expressjs/accepts)\n[![Coverage Status](https://img.shields.io/coveralls/expressjs/accepts.svg?branch=master)](https://coveralls.io/r/expressjs/accepts)\n\nHigher level content negotation based on [negotiator](https://github.com/federomero/negotiator). Extracted from [koa](https://github.com/koajs/koa) for general use.\n\nIn addition to negotatior, it allows:\n\n- Allows types as an array or arguments list, ie `(['text/html', 'application/json'])` as well as `('text/html', 'application/json')`.\n- Allows type shorthands such as `json`.\n- Returns `false` when no types match\n- Treats non-existent headers as `*`\n\n## API\n\n### var accept = new Accepts(req)\n\n```js\nvar accepts = require('accepts')\n\nhttp.createServer(function (req, res) {\n var accept = accepts(req)\n})\n```\n\n### accept\\[property\\]\\(\\)\n\nReturns all the explicitly accepted content property as an array in descending priority.\n\n- `accept.types()`\n- `accept.encodings()`\n- `accept.charsets()`\n- `accept.languages()`\n\nThey are also aliased in singular form such as `accept.type()`. `accept.languages()` is also aliased as `accept.langs()`, etc.\n\nNote: you should almost never do this in a real app as it defeats the purpose of content negotiation.\n\nExample:\n\n```js\n// in Google Chrome\nvar encodings = accept.encodings() // -> ['sdch', 'gzip', 'deflate']\n```\n\nSince you probably don't support `sdch`, you should just supply the encodings you support:\n\n```js\nvar encoding = accept.encodings('gzip', 'deflate') // -> 'gzip', probably\n```\n\n### accept\\[property\\]\\(values, ...\\)\n\nYou can either have `values` be an array or have an argument list of values.\n\nIf the client does not accept any `values`, `false` will be returned.\nIf the client accepts any `values`, the preferred `value` will be return.\n\nFor `accept.types()`, shorthand mime types are allowed.\n\nExample:\n\n```js\n// req.headers.accept = 'application/json'\n\naccept.types('json') // -> 'json'\naccept.types('html', 'json') // -> 'json'\naccept.types('html') // -> false\n\n// req.headers.accept = ''\n// which is equivalent to `*`\n\naccept.types() // -> [], no explicit types\naccept.types('text/html', 'text/json') // -> 'text/html', since it was first\n```\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2013 Jonathan Ong me@jongleberry.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.",
|
||||
"readmeFilename": "README.md",
|
||||
"bugs": {
|
||||
"url": "https://github.com/expressjs/accepts/issues"
|
||||
},
|
||||
"_id": "accepts@1.0.6",
|
||||
"_from": "accepts@~1.0.5"
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
node_modules
|
|
@ -0,0 +1,8 @@
|
|||
language: node_js
|
||||
node_js:
|
||||
- 0.6
|
||||
- 0.8
|
||||
notifications:
|
||||
email:
|
||||
recipients:
|
||||
- brianloveswords@gmail.com
|
|
@ -0,0 +1,17 @@
|
|||
Copyright (c) 2013 Brian J. Brennan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,47 @@
|
|||
# buffer-crc32
|
||||
|
||||
[![Build Status](https://secure.travis-ci.org/brianloveswords/buffer-crc32.png?branch=master)](http://travis-ci.org/brianloveswords/buffer-crc32)
|
||||
|
||||
crc32 that works with binary data and fancy character sets, outputs
|
||||
buffer, signed or unsigned data and has tests.
|
||||
|
||||
Derived from the sample CRC implementation in the PNG specification: http://www.w3.org/TR/PNG/#D-CRCAppendix
|
||||
|
||||
# install
|
||||
```
|
||||
npm install buffer-crc32
|
||||
```
|
||||
|
||||
# example
|
||||
```js
|
||||
var crc32 = require('buffer-crc32');
|
||||
// works with buffers
|
||||
var buf = Buffer([0x00, 0x73, 0x75, 0x70, 0x20, 0x62, 0x72, 0x6f, 0x00])
|
||||
crc32(buf) // -> <Buffer 94 5a ab 4a>
|
||||
|
||||
// has convenience methods for getting signed or unsigned ints
|
||||
crc32.signed(buf) // -> -1805997238
|
||||
crc32.unsigned(buf) // -> 2488970058
|
||||
|
||||
// will cast to buffer if given a string, so you can
|
||||
// directly use foreign characters safely
|
||||
crc32('自動販売機') // -> <Buffer cb 03 1a c5>
|
||||
|
||||
// and works in append mode too
|
||||
var partialCrc = crc32('hey');
|
||||
var partialCrc = crc32(' ', partialCrc);
|
||||
var partialCrc = crc32('sup', partialCrc);
|
||||
var partialCrc = crc32(' ', partialCrc);
|
||||
var finalCrc = crc32('bros', partialCrc); // -> <Buffer 47 fa 55 70>
|
||||
```
|
||||
|
||||
# tests
|
||||
This was tested against the output of zlib's crc32 method. You can run
|
||||
the tests with`npm test` (requires tap)
|
||||
|
||||
# see also
|
||||
https://github.com/alexgorbatchev/node-crc, `crc.buffer.crc32` also
|
||||
supports buffer inputs and return unsigned ints (thanks @tjholowaychuk).
|
||||
|
||||
# license
|
||||
MIT/X11
|
|
@ -0,0 +1,91 @@
|
|||
var Buffer = require('buffer').Buffer;
|
||||
|
||||
var CRC_TABLE = [
|
||||
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
|
||||
0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
|
||||
0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
|
||||
0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
|
||||
0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
|
||||
0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
|
||||
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
|
||||
0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
|
||||
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
|
||||
0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
|
||||
0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
|
||||
0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
|
||||
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
|
||||
0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
|
||||
0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
|
||||
0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
|
||||
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
|
||||
0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
|
||||
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
|
||||
0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
|
||||
0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
|
||||
0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
|
||||
0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
|
||||
0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
|
||||
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
|
||||
0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
|
||||
0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
|
||||
0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
|
||||
0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
|
||||
0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
|
||||
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
|
||||
0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
|
||||
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
|
||||
0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
|
||||
0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
|
||||
0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
|
||||
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
|
||||
0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
|
||||
0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
|
||||
0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
|
||||
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
|
||||
0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
|
||||
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
|
||||
0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
|
||||
0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
|
||||
0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
|
||||
0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
|
||||
0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
|
||||
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
|
||||
0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
|
||||
0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
|
||||
0x2d02ef8d
|
||||
];
|
||||
|
||||
if (typeof Int32Array !== 'undefined')
|
||||
CRC_TABLE = new Int32Array(CRC_TABLE);
|
||||
|
||||
function bufferizeInt(num) {
|
||||
var tmp = Buffer(4);
|
||||
tmp.writeInt32BE(num, 0);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
function _crc32(buf, previous) {
|
||||
if (!Buffer.isBuffer(buf)) {
|
||||
buf = Buffer(buf);
|
||||
}
|
||||
if (Buffer.isBuffer(previous)) {
|
||||
previous = previous.readUInt32BE(0);
|
||||
}
|
||||
var crc = ~~previous ^ -1;
|
||||
for (var n = 0; n < buf.length; n++) {
|
||||
crc = CRC_TABLE[(crc ^ buf[n]) & 0xff] ^ (crc >>> 8);
|
||||
}
|
||||
return (crc ^ -1);
|
||||
}
|
||||
|
||||
function crc32() {
|
||||
return bufferizeInt(_crc32.apply(null, arguments));
|
||||
}
|
||||
crc32.signed = function () {
|
||||
return _crc32.apply(null, arguments);
|
||||
};
|
||||
crc32.unsigned = function () {
|
||||
return _crc32.apply(null, arguments) >>> 0;
|
||||
};
|
||||
|
||||
module.exports = crc32;
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue