mirror of https://gitee.com/bigwinds/arangodb
return error message
This commit is contained in:
parent
1759b7d85a
commit
4059f31170
|
@ -1,5 +1,288 @@
|
|||
all:
|
||||
-@echo "Please use ./configure first. Thank you."
|
||||
# Makefile for zlib
|
||||
# Copyright (C) 1995-2011 Jean-loup Gailly.
|
||||
# For conditions of distribution and use, see copyright notice in zlib.h
|
||||
|
||||
distclean:
|
||||
make -f Makefile.in distclean
|
||||
# To compile and test, type:
|
||||
# ./configure; make test
|
||||
# Normally configure builds both a static and a shared library.
|
||||
# If you want to build just a static library, use: ./configure --static
|
||||
|
||||
# To use the asm code, type:
|
||||
# cp contrib/asm?86/match.S ./match.S
|
||||
# make LOC=-DASMV OBJA=match.o
|
||||
|
||||
# To install /usr/local/lib/libz.* and /usr/local/include/zlib.h, type:
|
||||
# make install
|
||||
# To install in $HOME instead of /usr/local, use:
|
||||
# make install prefix=$HOME
|
||||
|
||||
CC=gcc
|
||||
|
||||
CFLAGS=-g -DHAVE_HIDDEN
|
||||
#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
|
||||
#CFLAGS=-g -DDEBUG
|
||||
#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
|
||||
# -Wstrict-prototypes -Wmissing-prototypes
|
||||
|
||||
SFLAGS=-g -fPIC -DHAVE_HIDDEN
|
||||
LDFLAGS=
|
||||
TEST_LDFLAGS=-L. libz.a
|
||||
LDSHARED=gcc -dynamiclib -install_name ${exec_prefix}/lib/libz.1.dylib -compatibility_version 1 -current_version 1.2.7
|
||||
CPP=gcc -E
|
||||
|
||||
STATICLIB=libz.a
|
||||
SHAREDLIB=libz.dylib
|
||||
SHAREDLIBV=libz.1.2.7.dylib
|
||||
SHAREDLIBM=libz.1.dylib
|
||||
LIBS=$(STATICLIB) $(SHAREDLIBV)
|
||||
|
||||
AR=/usr/bin/libtool
|
||||
ARFLAGS=-o
|
||||
RANLIB=ranlib
|
||||
LDCONFIG=ldconfig
|
||||
LDSHAREDLIBC=-lc
|
||||
TAR=tar
|
||||
SHELL=/bin/sh
|
||||
EXE=
|
||||
|
||||
prefix =/usr/local
|
||||
exec_prefix =${prefix}
|
||||
libdir =${exec_prefix}/lib
|
||||
sharedlibdir =${libdir}
|
||||
includedir =${prefix}/include
|
||||
mandir =${prefix}/share/man
|
||||
man3dir = ${mandir}/man3
|
||||
pkgconfigdir = ${libdir}/pkgconfig
|
||||
|
||||
OBJZ = adler32.o crc32.o deflate.o infback.o inffast.o inflate.o inftrees.o trees.o zutil.o
|
||||
OBJG = compress.o uncompr.o gzclose.o gzlib.o gzread.o gzwrite.o
|
||||
OBJC = $(OBJZ) $(OBJG)
|
||||
|
||||
PIC_OBJZ = adler32.lo crc32.lo deflate.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo zutil.lo
|
||||
PIC_OBJG = compress.lo uncompr.lo gzclose.lo gzlib.lo gzread.lo gzwrite.lo
|
||||
PIC_OBJC = $(PIC_OBJZ) $(PIC_OBJG)
|
||||
|
||||
# to use the asm code: make OBJA=match.o, PIC_OBJA=match.lo
|
||||
OBJA =
|
||||
PIC_OBJA =
|
||||
|
||||
OBJS = $(OBJC) $(OBJA)
|
||||
|
||||
PIC_OBJS = $(PIC_OBJC) $(PIC_OBJA)
|
||||
|
||||
all: static shared
|
||||
|
||||
static: example$(EXE) minigzip$(EXE)
|
||||
|
||||
shared: examplesh$(EXE) minigzipsh$(EXE)
|
||||
|
||||
all64: example64$(EXE) minigzip64$(EXE)
|
||||
|
||||
check: test
|
||||
|
||||
test: all teststatic testshared
|
||||
|
||||
teststatic: static
|
||||
@TMPST=`mktemp fooXXXXXX`; \
|
||||
if echo hello world | ./minigzip | ./minigzip -d && ./example $$TMPST ; then \
|
||||
echo ' *** zlib test OK ***'; \
|
||||
else \
|
||||
echo ' *** zlib test FAILED ***'; false; \
|
||||
fi; \
|
||||
rm -f $$TMPST
|
||||
|
||||
testshared: shared
|
||||
@LD_LIBRARY_PATH=`pwd`:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \
|
||||
LD_LIBRARYN32_PATH=`pwd`:$(LD_LIBRARYN32_PATH) ; export LD_LIBRARYN32_PATH; \
|
||||
DYLD_LIBRARY_PATH=`pwd`:$(DYLD_LIBRARY_PATH) ; export DYLD_LIBRARY_PATH; \
|
||||
SHLIB_PATH=`pwd`:$(SHLIB_PATH) ; export SHLIB_PATH; \
|
||||
TMPSH=`mktemp fooXXXXXX`; \
|
||||
if echo hello world | ./minigzipsh | ./minigzipsh -d && ./examplesh $$TMPSH; then \
|
||||
echo ' *** zlib shared test OK ***'; \
|
||||
else \
|
||||
echo ' *** zlib shared test FAILED ***'; false; \
|
||||
fi; \
|
||||
rm -f $$TMPSH
|
||||
|
||||
test64: all64
|
||||
@TMP64=`mktemp fooXXXXXX`; \
|
||||
if echo hello world | ./minigzip64 | ./minigzip64 -d && ./example64 $$TMP64; then \
|
||||
echo ' *** zlib 64-bit test OK ***'; \
|
||||
else \
|
||||
echo ' *** zlib 64-bit test FAILED ***'; false; \
|
||||
fi; \
|
||||
rm -f $$TMP64
|
||||
|
||||
infcover.o: test/infcover.c zlib.h zconf.h
|
||||
$(CC) $(CFLAGS) -I. -c -o $@ test/infcover.c
|
||||
|
||||
infcover: infcover.o libz.a
|
||||
$(CC) $(CFLAGS) -o $@ infcover.o libz.a
|
||||
|
||||
cover: infcover
|
||||
rm -f *.gcda
|
||||
./infcover
|
||||
gcov inf*.c
|
||||
|
||||
libz.a: $(OBJS)
|
||||
$(AR) $(ARFLAGS) $@ $(OBJS)
|
||||
-@ ($(RANLIB) $@ || true) >/dev/null 2>&1
|
||||
|
||||
match.o: match.S
|
||||
$(CPP) match.S > _match.s
|
||||
$(CC) -c _match.s
|
||||
mv _match.o match.o
|
||||
rm -f _match.s
|
||||
|
||||
match.lo: match.S
|
||||
$(CPP) match.S > _match.s
|
||||
$(CC) -c -fPIC _match.s
|
||||
mv _match.o match.lo
|
||||
rm -f _match.s
|
||||
|
||||
example.o: test/example.c zlib.h zconf.h
|
||||
$(CC) $(CFLAGS) -I. -c -o $@ test/example.c
|
||||
|
||||
minigzip.o: test/minigzip.c zlib.h zconf.h
|
||||
$(CC) $(CFLAGS) -I. -c -o $@ test/minigzip.c
|
||||
|
||||
example64.o: test/example.c zlib.h zconf.h
|
||||
$(CC) $(CFLAGS) -I. -D_FILE_OFFSET_BITS=64 -c -o $@ test/example.c
|
||||
|
||||
minigzip64.o: test/minigzip.c zlib.h zconf.h
|
||||
$(CC) $(CFLAGS) -I. -D_FILE_OFFSET_BITS=64 -c -o $@ test/minigzip.c
|
||||
|
||||
.SUFFIXES: .lo
|
||||
|
||||
.c.lo:
|
||||
-@mkdir objs 2>/dev/null || test -d objs
|
||||
$(CC) $(SFLAGS) -DPIC -c -o objs/$*.o $<
|
||||
-@mv objs/$*.o $@
|
||||
|
||||
placebo $(SHAREDLIBV): $(PIC_OBJS) libz.a
|
||||
$(LDSHARED) $(SFLAGS) -o $@ $(PIC_OBJS) $(LDSHAREDLIBC) $(LDFLAGS)
|
||||
rm -f $(SHAREDLIB) $(SHAREDLIBM)
|
||||
ln -s $@ $(SHAREDLIB)
|
||||
ln -s $@ $(SHAREDLIBM)
|
||||
-@rmdir objs
|
||||
|
||||
example$(EXE): example.o $(STATICLIB)
|
||||
$(CC) $(CFLAGS) -o $@ example.o $(TEST_LDFLAGS)
|
||||
|
||||
minigzip$(EXE): minigzip.o $(STATICLIB)
|
||||
$(CC) $(CFLAGS) -o $@ minigzip.o $(TEST_LDFLAGS)
|
||||
|
||||
examplesh$(EXE): example.o $(SHAREDLIBV)
|
||||
$(CC) $(CFLAGS) -o $@ example.o -L. $(SHAREDLIBV)
|
||||
|
||||
minigzipsh$(EXE): minigzip.o $(SHAREDLIBV)
|
||||
$(CC) $(CFLAGS) -o $@ minigzip.o -L. $(SHAREDLIBV)
|
||||
|
||||
example64$(EXE): example64.o $(STATICLIB)
|
||||
$(CC) $(CFLAGS) -o $@ example64.o $(TEST_LDFLAGS)
|
||||
|
||||
minigzip64$(EXE): minigzip64.o $(STATICLIB)
|
||||
$(CC) $(CFLAGS) -o $@ minigzip64.o $(TEST_LDFLAGS)
|
||||
|
||||
install-libs: $(LIBS)
|
||||
-@if [ ! -d $(DESTDIR)$(exec_prefix) ]; then mkdir -p $(DESTDIR)$(exec_prefix); fi
|
||||
-@if [ ! -d $(DESTDIR)$(libdir) ]; then mkdir -p $(DESTDIR)$(libdir); fi
|
||||
-@if [ ! -d $(DESTDIR)$(sharedlibdir) ]; then mkdir -p $(DESTDIR)$(sharedlibdir); fi
|
||||
-@if [ ! -d $(DESTDIR)$(man3dir) ]; then mkdir -p $(DESTDIR)$(man3dir); fi
|
||||
-@if [ ! -d $(DESTDIR)$(pkgconfigdir) ]; then mkdir -p $(DESTDIR)$(pkgconfigdir); fi
|
||||
cp $(STATICLIB) $(DESTDIR)$(libdir)
|
||||
chmod 644 $(DESTDIR)$(libdir)/$(STATICLIB)
|
||||
-@($(RANLIB) $(DESTDIR)$(libdir)/libz.a || true) >/dev/null 2>&1
|
||||
-@if test -n "$(SHAREDLIBV)"; then \
|
||||
cp $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir); \
|
||||
echo "cp $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)"; \
|
||||
chmod 755 $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBV); \
|
||||
echo "chmod 755 $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBV)"; \
|
||||
rm -f $(DESTDIR)$(sharedlibdir)/$(SHAREDLIB) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBM); \
|
||||
ln -s $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIB); \
|
||||
ln -s $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBM); \
|
||||
($(LDCONFIG) || true) >/dev/null 2>&1; \
|
||||
fi
|
||||
cp zlib.3 $(DESTDIR)$(man3dir)
|
||||
chmod 644 $(DESTDIR)$(man3dir)/zlib.3
|
||||
cp zlib.pc $(DESTDIR)$(pkgconfigdir)
|
||||
chmod 644 $(DESTDIR)$(pkgconfigdir)/zlib.pc
|
||||
# The ranlib in install is needed on NeXTSTEP which checks file times
|
||||
# ldconfig is for Linux
|
||||
|
||||
install: install-libs
|
||||
-@if [ ! -d $(DESTDIR)$(includedir) ]; then mkdir -p $(DESTDIR)$(includedir); fi
|
||||
cp zlib.h zconf.h $(DESTDIR)$(includedir)
|
||||
chmod 644 $(DESTDIR)$(includedir)/zlib.h $(DESTDIR)$(includedir)/zconf.h
|
||||
|
||||
uninstall:
|
||||
cd $(DESTDIR)$(includedir); rm -f zlib.h zconf.h
|
||||
cd $(DESTDIR)$(libdir); rm -f libz.a; \
|
||||
if test -n "$(SHAREDLIBV)" -a -f $(SHAREDLIBV); then \
|
||||
rm -f $(SHAREDLIBV) $(SHAREDLIB) $(SHAREDLIBM); \
|
||||
fi
|
||||
cd $(DESTDIR)$(man3dir); rm -f zlib.3
|
||||
cd $(DESTDIR)$(pkgconfigdir); rm -f zlib.pc
|
||||
|
||||
docs: zlib.3.pdf
|
||||
|
||||
zlib.3.pdf: zlib.3
|
||||
groff -mandoc -f H -T ps zlib.3 | ps2pdf - zlib.3.pdf
|
||||
|
||||
zconf.h.cmakein: zconf.h.in
|
||||
-@ TEMPFILE=`mktemp __XXXXXX`; \
|
||||
echo "/#define ZCONF_H/ a\\\\\n#cmakedefine Z_PREFIX\\\\\n#cmakedefine Z_HAVE_UNISTD_H\n" >> $$TEMPFILE &&\
|
||||
sed -f $$TEMPFILE zconf.h.in > zconf.h.cmakein &&\
|
||||
touch -r zconf.h.in zconf.h.cmakein &&\
|
||||
rm $$TEMPFILE
|
||||
|
||||
zconf: zconf.h.in
|
||||
cp -p zconf.h.in zconf.h
|
||||
|
||||
mostlyclean: clean
|
||||
clean:
|
||||
rm -f *.o *.lo *~ \
|
||||
example$(EXE) minigzip$(EXE) examplesh$(EXE) minigzipsh$(EXE) \
|
||||
example64$(EXE) minigzip64$(EXE) \
|
||||
infcover \
|
||||
libz.* foo.gz so_locations \
|
||||
_match.s maketree contrib/infback9/*.o
|
||||
rm -rf objs
|
||||
rm -f *.gcda *.gcno *.gcov
|
||||
rm -f contrib/infback9/*.gcda contrib/infback9/*.gcno contrib/infback9/*.gcov
|
||||
|
||||
maintainer-clean: distclean
|
||||
distclean: clean zconf zconf.h.cmakein docs
|
||||
rm -f Makefile zlib.pc configure.log
|
||||
-@rm -f .DS_Store
|
||||
-@printf 'all:\n\t-@echo "Please use ./configure first. Thank you."\n' > Makefile
|
||||
-@printf '\ndistclean:\n\tmake -f Makefile.in distclean\n' >> Makefile
|
||||
-@touch -r Makefile.in Makefile
|
||||
|
||||
tags:
|
||||
etags *.[ch]
|
||||
|
||||
depend:
|
||||
makedepend -- $(CFLAGS) -- *.[ch]
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
adler32.o zutil.o: zutil.h zlib.h zconf.h
|
||||
gzclose.o gzlib.o gzread.o gzwrite.o: zlib.h zconf.h gzguts.h
|
||||
compress.o example.o minigzip.o uncompr.o: zlib.h zconf.h
|
||||
crc32.o: zutil.h zlib.h zconf.h crc32.h
|
||||
deflate.o: deflate.h zutil.h zlib.h zconf.h
|
||||
infback.o inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h inffixed.h
|
||||
inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
|
||||
inftrees.o: zutil.h zlib.h zconf.h inftrees.h
|
||||
trees.o: deflate.h zutil.h zlib.h zconf.h trees.h
|
||||
|
||||
adler32.lo zutil.lo: zutil.h zlib.h zconf.h
|
||||
gzclose.lo gzlib.lo gzread.lo gzwrite.lo: zlib.h zconf.h gzguts.h
|
||||
compress.lo example.lo minigzip.lo uncompr.lo: zlib.h zconf.h
|
||||
crc32.lo: zutil.h zlib.h zconf.h crc32.h
|
||||
deflate.lo: deflate.h zutil.h zlib.h zconf.h
|
||||
infback.lo inflate.lo: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h inffixed.h
|
||||
inffast.lo: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
|
||||
inftrees.lo: zutil.h zlib.h zconf.h inftrees.h
|
||||
trees.lo: deflate.h zutil.h zlib.h zconf.h trees.h
|
||||
|
|
|
@ -132,6 +132,19 @@
|
|||
throw "not connected";
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief execute javascript file on the server
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
internal.executeServer = function (body) {
|
||||
if (typeof internal.arango !== 'undefined') {
|
||||
internal.arango.POST("/_admin/execute", body);
|
||||
return;
|
||||
}
|
||||
|
||||
throw "not connected";
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief logs a request in curl format
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -138,8 +138,7 @@
|
|||
|
||||
internal.executeServer = function (body) {
|
||||
if (typeof internal.arango !== 'undefined') {
|
||||
internal.arango.POST("/_admin/execute", body);
|
||||
return;
|
||||
return internal.arango.POST("/_admin/execute", body);
|
||||
}
|
||||
|
||||
throw "not connected";
|
||||
|
|
|
@ -429,9 +429,9 @@ function stop_color_print () {
|
|||
|
||||
paths = pkg._paths;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------
|
||||
// normal modules, file based
|
||||
// -----------------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// try to load the file
|
||||
for (i = 0; i < paths.length; ++i) {
|
||||
|
@ -469,9 +469,9 @@ function stop_color_print () {
|
|||
|
||||
paths = internal.MODULES_PATH;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------
|
||||
// normal modules, file based
|
||||
// -----------------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// try to load the file
|
||||
for (i = 0; i < paths.length; ++i) {
|
||||
|
@ -494,9 +494,9 @@ function stop_color_print () {
|
|||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------
|
||||
// normal modules, database based
|
||||
// -----------------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
if (internal.db !== undefined) {
|
||||
mc = internal.db._collection("_modules");
|
||||
|
@ -726,6 +726,56 @@ function stop_color_print () {
|
|||
+ " and package path '" + this._package._paths + "'";
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief loads a file from an application path
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Module.prototype.loadAppScript = function (unormalizedPath, manifest, appfile) {
|
||||
var fun;
|
||||
var result;
|
||||
var path = this.normalize(unormalizedPath);
|
||||
var pkg = new Package("application",
|
||||
{name: "application '" + appfile + "'"},
|
||||
undefined,
|
||||
path);
|
||||
var mdl = new Module("application", 'application', pkg);
|
||||
var file = this.normalize(path + "/" + appfile);
|
||||
var content;
|
||||
var sandbox = {};
|
||||
|
||||
try {
|
||||
content = internal.read(file);
|
||||
}
|
||||
catch (err) {
|
||||
throw "cannot read file '" + file + "': " + err + " - " + err.stack;
|
||||
}
|
||||
|
||||
sandbox.module = mdl;
|
||||
|
||||
sandbox.require = function (path) {
|
||||
return mdl.require(path);
|
||||
};
|
||||
|
||||
content = "var func = function () {"
|
||||
+ content
|
||||
+ "\n};";
|
||||
|
||||
fun = internal.execute(content, sandbox, appfile);
|
||||
|
||||
if (fun !== true || ! sandbox.hasOwnProperty("func")) {
|
||||
throw "cannot create application function";
|
||||
}
|
||||
|
||||
try {
|
||||
result = sandbox.func();
|
||||
}
|
||||
catch (err) {
|
||||
throw "Javascript exception in application file '" + appfile + "': " + err + " - " + err.stack;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns true if require found a file
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -19,541 +19,28 @@ var FuxxApplication,
|
|||
console = require("console"),
|
||||
internal = {};
|
||||
|
||||
// ArangoDB uses a certain structure we refer to as `UrlObject`.
|
||||
// With the following function (which is only internal, and not
|
||||
// exported) you can create an UrlObject with a given URL,
|
||||
// a constraint and a method. For example:
|
||||
//
|
||||
// internal.createUrlObject('/lecker/gans', null, 'get')
|
||||
internal.createUrlObject = function (url, constraint, method) {
|
||||
'use strict';
|
||||
var urlObject = {};
|
||||
|
||||
if (!_.isString(url)) {
|
||||
throw "URL has to be a String";
|
||||
}
|
||||
|
||||
urlObject.match = url;
|
||||
urlObject.methods = [method];
|
||||
|
||||
if (!_.isNull(constraint)) {
|
||||
urlObject.constraint = constraint;
|
||||
}
|
||||
|
||||
return urlObject;
|
||||
};
|
||||
|
||||
// ## Creating a new Application
|
||||
// And that's FuxxApplication. It's a constructor, so call it like this:
|
||||
//
|
||||
// app = new FuxxApplication({
|
||||
// urlPrefix: "/wiese",
|
||||
// templateCollection: "my_templates"
|
||||
// })
|
||||
//
|
||||
// It takes two optional arguments as displayed above:
|
||||
//
|
||||
// * **The URL Prefix:** All routes you define within will be prefixed with it
|
||||
// * **The Template Collection:** More information in the template section
|
||||
FuxxApplication = function (options) {
|
||||
'use strict';
|
||||
var urlPrefix, templateCollection, myMiddleware;
|
||||
|
||||
options = options || {};
|
||||
|
||||
urlPrefix = options.urlPrefix;
|
||||
templateCollection = options.templateCollection;
|
||||
|
||||
this.routingInfo = {
|
||||
routes: []
|
||||
};
|
||||
|
||||
this.helperCollection = {};
|
||||
|
||||
if (_.isString(urlPrefix)) {
|
||||
this.routingInfo.urlPrefix = urlPrefix;
|
||||
}
|
||||
|
||||
if (_.isString(templateCollection)) {
|
||||
this.routingInfo.templateCollection = db._collection(templateCollection) ||
|
||||
db._create(templateCollection);
|
||||
myMiddleware = new BaseMiddleware(templateCollection, this.helperCollection);
|
||||
} else {
|
||||
myMiddleware = new BaseMiddleware();
|
||||
}
|
||||
|
||||
this.routingInfo.middleware = [
|
||||
{
|
||||
url: {match: "/*"},
|
||||
action: {callback: myMiddleware}
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
// ## The functions on a created FuxxApplication
|
||||
//
|
||||
// When you have created your FuxxApplication you can now define routes
|
||||
// on it. You provide each with a function that will handle
|
||||
// the request. It gets two arguments (four, to be honest. But the
|
||||
// other two are not relevant for now):
|
||||
//
|
||||
// * The request object
|
||||
// * The response object
|
||||
//
|
||||
// You can find more about those in their individual sections.
|
||||
_.extend(FuxxApplication.prototype, {
|
||||
// The `handleRequest` method is the raw way to create a new
|
||||
// route. You probably wont call it directly, but it is used
|
||||
// in the other request methods:
|
||||
//
|
||||
// app.handleRequest("get", "/gaense", function (req, res) {
|
||||
// //handle the request
|
||||
// });
|
||||
handleRequest: function (method, route, argument1, argument2) {
|
||||
'use strict';
|
||||
var newRoute = {}, options, callback;
|
||||
|
||||
if (_.isUndefined(argument2)) {
|
||||
callback = argument1;
|
||||
options = {};
|
||||
} else {
|
||||
options = argument1;
|
||||
callback = argument2;
|
||||
}
|
||||
|
||||
newRoute.url = internal.createUrlObject(route, options.constraint, method);
|
||||
newRoute.action = {
|
||||
callback: String(callback)
|
||||
};
|
||||
|
||||
this.routingInfo.routes.push(newRoute);
|
||||
},
|
||||
|
||||
// ### Handle a `head` request
|
||||
// This handles requests from the HTTP verb `head`.
|
||||
// As with all other requests you can give an option as the third
|
||||
// argument, or leave it blank. You have to give a function as
|
||||
// the last argument however. It will get a request and response
|
||||
// object as its arguments
|
||||
head: function (route, argument1, argument2) {
|
||||
'use strict';
|
||||
this.handleRequest("head", route, argument1, argument2);
|
||||
},
|
||||
|
||||
// ### Manage a `get` request
|
||||
// This handles requests from the HTTP verb `get`.
|
||||
// See above for the arguments you can give. An example:
|
||||
//
|
||||
// app.get('/gaense/stall', function (req, res) {
|
||||
// // Take this request and deal with it!
|
||||
// });
|
||||
get: function (route, argument1, argument2) {
|
||||
'use strict';
|
||||
this.handleRequest("get", route, argument1, argument2);
|
||||
},
|
||||
|
||||
// ### Tackle a `post` request
|
||||
// This handles requests from the HTTP verb `post`.
|
||||
// See above for the arguments you can give. An example:
|
||||
//
|
||||
// app.post('/gaense/stall', function (req, res) {
|
||||
// // Take this request and deal with it!
|
||||
// });
|
||||
post: function (route, argument1, argument2) {
|
||||
'use strict';
|
||||
this.handleRequest("post", route, argument1, argument2);
|
||||
},
|
||||
|
||||
// ### Sort out a `put` request
|
||||
// This handles requests from the HTTP verb `put`.
|
||||
// See above for the arguments you can give. An example:
|
||||
//
|
||||
// app.put('/gaense/stall', function (req, res) {
|
||||
// // Take this request and deal with it!
|
||||
// });
|
||||
put: function (route, argument1, argument2) {
|
||||
'use strict';
|
||||
this.handleRequest("put", route, argument1, argument2);
|
||||
},
|
||||
|
||||
// ### Take charge of a `patch` request
|
||||
// This handles requests from the HTTP verb `patch`.
|
||||
// See above for the arguments you can give. An example:
|
||||
//
|
||||
// app.patch('/gaense/stall', function (req, res) {
|
||||
// // Take this request and deal with it!
|
||||
// });
|
||||
patch: function (route, argument1, argument2) {
|
||||
'use strict';
|
||||
this.handleRequest("patch", route, argument1, argument2);
|
||||
},
|
||||
|
||||
// ### Respond to a `delete` request
|
||||
// This handles requests from the HTTP verb `delete`.
|
||||
// See above for the arguments you can give.
|
||||
// **A word of warning:** Do not forget that `delete` is
|
||||
// a reserved word in JavaScript so call it as follows:
|
||||
//
|
||||
// app['delete']('/gaense/stall', function (req, res) {
|
||||
// // Take this request and deal with it!
|
||||
// });
|
||||
'delete': function (route, argument1, argument2) {
|
||||
'use strict';
|
||||
this.handleRequest("delete", route, argument1, argument2);
|
||||
},
|
||||
|
||||
// ## Before and After Hooks
|
||||
// You can use the following two functions to do something
|
||||
// before or respectively after the normal routing process
|
||||
// is happening. You could use that for logging or to manipulate
|
||||
// the request or response (translate it to a certain format for
|
||||
// example).
|
||||
|
||||
// ### Before
|
||||
// The before function takes a path on which it should watch
|
||||
// and a function that it should execute before the routing
|
||||
// takes place. If you do omit the path, the function will
|
||||
// be executed before each request, no matter the path.
|
||||
// Your function gets a Request and a Response object.
|
||||
// An example:
|
||||
//
|
||||
// app.before('/high/way', function(req, res) {
|
||||
// //Do some crazy request logging
|
||||
// });
|
||||
before: function (path, func) {
|
||||
'use strict';
|
||||
if (_.isUndefined(func)) {
|
||||
func = path;
|
||||
path = "/*";
|
||||
}
|
||||
|
||||
this.routingInfo.middleware.push({
|
||||
url: {match: path},
|
||||
action: {callback: function (req, res, opts, next) {
|
||||
func(req, res);
|
||||
next();
|
||||
}}
|
||||
});
|
||||
},
|
||||
|
||||
// ### After
|
||||
// This works pretty similar to the before function.
|
||||
// But it acts after the execution of the handlers
|
||||
// (Big surprise, I suppose).
|
||||
//
|
||||
// An example:
|
||||
//
|
||||
// app.after('/high/way', function(req, res) {
|
||||
// //Do some crazy response logging
|
||||
// });
|
||||
after: function (path, func) {
|
||||
'use strict';
|
||||
if (_.isUndefined(func)) {
|
||||
func = path;
|
||||
path = "/*";
|
||||
}
|
||||
|
||||
this.routingInfo.middleware.push({
|
||||
url: {match: path},
|
||||
action: {callback: function (req, res, opts, next) {
|
||||
next();
|
||||
func(req, res);
|
||||
}}
|
||||
});
|
||||
},
|
||||
|
||||
// ## The ViewHelper concept
|
||||
// If you want to use a function inside your templates, the ViewHelpers
|
||||
// will come to rescue you. Define them on your app like this:
|
||||
//
|
||||
// app.helper("link_to", function (identifier) {
|
||||
// return urlRepository[identifier];
|
||||
// });
|
||||
//
|
||||
// Then you can just call this function in your template's JavaScript
|
||||
// blocks.
|
||||
helper: function (name, func) {
|
||||
'use strict';
|
||||
this.helperCollection[name] = func;
|
||||
},
|
||||
|
||||
// ## Shortform for using the FormatMiddleware
|
||||
//
|
||||
// More information about the FormatMiddleware in the corresponding section.
|
||||
// This is a shortcut to add the middleware to your application:
|
||||
//
|
||||
// app.accepts(["json"], "json");
|
||||
accepts: function (allowedFormats, defaultFormat) {
|
||||
'use strict';
|
||||
|
||||
this.routingInfo.middleware.push({
|
||||
url: { match: "/*" },
|
||||
action: { callback: new FormatMiddleware(allowedFormats, defaultFormat) }
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// ## The Base Middleware
|
||||
// The `BaseMiddleware` manipulates the request and response
|
||||
// objects to give you a nicer API.
|
||||
BaseMiddleware = function (templateCollection, helperCollection) {
|
||||
'use strict';
|
||||
var middleware = function (request, response, options, next) {
|
||||
var responseFunctions, requestFunctions;
|
||||
|
||||
// ### The Request Object
|
||||
// Every request object has the following attributes from the underlying Actions:
|
||||
//
|
||||
// * path: The complete path as supplied by the user
|
||||
// * prefix
|
||||
// * suffix
|
||||
// * urlParameters
|
||||
//
|
||||
// FuxxApplication currently leaves those unmodified.
|
||||
responseFunctions = {};
|
||||
|
||||
// ### The Response Object
|
||||
// Every response object has the following attributes from the underlying Actions:
|
||||
//
|
||||
// * contentType
|
||||
// * responseCode
|
||||
// * body
|
||||
// * headers (an object)
|
||||
//
|
||||
// FuxxApplication adds the following methods to this response object.
|
||||
responseFunctions = {
|
||||
// ### The straightforward `status` function
|
||||
// Set the status code of your response, for example:
|
||||
//
|
||||
// response.status(404);
|
||||
status: function (code) {
|
||||
this.responseCode = code;
|
||||
},
|
||||
|
||||
// ### The radical `set` function
|
||||
// Set a header attribute, for example:
|
||||
//
|
||||
// response.set("Content-Length", 123);
|
||||
// response.set("Content-Type", "text/plain");
|
||||
//
|
||||
// or alternatively:
|
||||
//
|
||||
// response.set({
|
||||
// "Content-Length": "123",
|
||||
// "Content-Type": "text/plain"
|
||||
// });
|
||||
set: function (key, value) {
|
||||
var attributes = {};
|
||||
if (_.isUndefined(value)) {
|
||||
attributes = key;
|
||||
} else {
|
||||
attributes[key] = value;
|
||||
}
|
||||
|
||||
_.each(attributes, function (value, key) {
|
||||
key = key.toLowerCase();
|
||||
this.headers = this.headers || {};
|
||||
this.headers[key] = value;
|
||||
|
||||
if (key === "content-type") {
|
||||
this.contentType = value;
|
||||
}
|
||||
}, this);
|
||||
},
|
||||
|
||||
// ### The magical `json` function
|
||||
// Set the content type to JSON and the body to the
|
||||
// JSON encoded object you provided.
|
||||
//
|
||||
// response.json({'born': 'December 12, 1915'});
|
||||
json: function (obj) {
|
||||
this.contentType = "application/json";
|
||||
this.body = JSON.stringify(obj);
|
||||
},
|
||||
|
||||
// ### The mysterious `render` function
|
||||
// If you initialize your FuxxApplication with a `templateCollection`,
|
||||
// you're in luck now.
|
||||
// It expects documents in the following form in this collection:
|
||||
//
|
||||
// {
|
||||
// path: "high/way",
|
||||
// content: "hallo <%= username %>",
|
||||
// contentType: "text/plain",
|
||||
// templateLanguage: "underscore"
|
||||
// }
|
||||
//
|
||||
// The `content` is the string that will be rendered by the template
|
||||
// processor. The `contentType` is the type of content that results
|
||||
// from this call. And with the `templateLanguage` you can choose
|
||||
// your template processor. There is only one choice now: `underscore`.
|
||||
//
|
||||
// If you call render, FuxxApplication will look
|
||||
// into the this collection and search by the path attribute.
|
||||
// It will then render the template with the given data:
|
||||
//
|
||||
// response.render("high/way", {username: 'FuxxApplication'})
|
||||
//
|
||||
// Which would set the body of the response to `hello FuxxApplication` with the
|
||||
// template defined above. It will also set the `contentType` to
|
||||
// `text/plain` in this case.
|
||||
//
|
||||
// In addition to the attributes you provided, you also have access to
|
||||
// all your view helpers. How to define them? Read above in the
|
||||
// ViewHelper section.
|
||||
render: function (templatePath, data) {
|
||||
var template;
|
||||
|
||||
if (_.isUndefined(templateCollection)) {
|
||||
throw "No template collection has been provided when creating a new FuxxApplication";
|
||||
}
|
||||
|
||||
template = templateCollection.firstExample({path: templatePath });
|
||||
|
||||
if (_.isNull(template)) {
|
||||
throw "Template '" + templatePath + "' does not exist";
|
||||
}
|
||||
|
||||
if (template.templateLanguage !== "underscore") {
|
||||
throw "Unknown template language '" + template.templateLanguage + "'";
|
||||
}
|
||||
|
||||
this.body = _.template(template.content, _.extend(data, helperCollection));
|
||||
this.contentType = template.contentType;
|
||||
}
|
||||
};
|
||||
|
||||
// Now enhance the request and response as described above and call next at the
|
||||
// end of this middleware (otherwise your application would never
|
||||
// be executed. Would be a shame, really).
|
||||
request = _.extend(request, requestFunctions);
|
||||
response = _.extend(response, responseFunctions);
|
||||
next();
|
||||
};
|
||||
|
||||
return middleware;
|
||||
};
|
||||
|
||||
// ## The Format Middleware
|
||||
// Unlike the `BaseMiddleware` this Middleware is only loaded if you
|
||||
// want it. This Middleware gives you Rails-like format handling via
|
||||
// the `extension` of the URL or the accept header.
|
||||
// Say you request an URL like `/people.json`:
|
||||
// The `FormatMiddleware` will set the format of the request to JSON
|
||||
// and then delete the `.json` from the request. You can therefore write
|
||||
// handlers that do not take an `extension` into consideration and instead
|
||||
// handle the format via a simple String.
|
||||
// To determine the format of the request it checks the URL and then
|
||||
// the `accept` header. If one of them gives a format or both give
|
||||
// the same, the format is set. If the formats are not the same,
|
||||
// an error is raised.
|
||||
//
|
||||
// Use it by calling:
|
||||
//
|
||||
// FormatMiddleware = require('fuxx').FormatMiddleware;
|
||||
// app.before("/*", FormatMiddleware.new(['json']));
|
||||
//
|
||||
// or the shortcut:
|
||||
//
|
||||
// app.accepts(['json']);
|
||||
//
|
||||
// In both forms you can give a default format as a second parameter,
|
||||
// if no format could be determined. If you give no `defaultFormat` this
|
||||
// case will be handled as an error.
|
||||
FormatMiddleware = function (allowedFormats, defaultFormat) {
|
||||
'use strict';
|
||||
var middleware, urlFormatToMime, mimeToUrlFormat, determinePathAndFormat;
|
||||
|
||||
urlFormatToMime = {
|
||||
json: "application/json",
|
||||
html: "text/html",
|
||||
txt: "text/plain"
|
||||
};
|
||||
|
||||
mimeToUrlFormat = {
|
||||
"application/json": "json",
|
||||
"text/html": "html",
|
||||
"text/plain": "txt"
|
||||
};
|
||||
|
||||
determinePathAndFormat = function (path, headers) {
|
||||
var parsed = {
|
||||
contentType: headers.accept
|
||||
};
|
||||
path = path.split('.');
|
||||
|
||||
if (path.length === 1) {
|
||||
parsed.path = path.join();
|
||||
} else {
|
||||
parsed.format = path.pop();
|
||||
parsed.path = path.join('.');
|
||||
}
|
||||
|
||||
if (parsed.contentType === undefined && parsed.format === undefined) {
|
||||
parsed.format = defaultFormat;
|
||||
parsed.contentType = urlFormatToMime[defaultFormat];
|
||||
} else if (parsed.contentType === undefined) {
|
||||
parsed.contentType = urlFormatToMime[parsed.format];
|
||||
} else if (parsed.format === undefined) {
|
||||
parsed.format = mimeToUrlFormat[parsed.contentType];
|
||||
}
|
||||
|
||||
if (parsed.format !== mimeToUrlFormat[parsed.contentType]) {
|
||||
parsed.error = "Contradiction between Accept Header and URL.";
|
||||
}
|
||||
|
||||
if (allowedFormats.indexOf(parsed.format) < 0) {
|
||||
parsed.error = "Format '" + parsed.format + "' is not allowed.";
|
||||
}
|
||||
|
||||
return parsed;
|
||||
};
|
||||
|
||||
middleware = function (request, response, options, next) {
|
||||
var parsed = determinePathAndFormat(request.path, request.headers);
|
||||
|
||||
if (parsed.error === undefined) {
|
||||
request.path = parsed.path;
|
||||
request.format = parsed.format;
|
||||
response.contentType = parsed.contentType;
|
||||
next();
|
||||
} else {
|
||||
response.responseCode = 406;
|
||||
response.body = parsed.error;
|
||||
}
|
||||
};
|
||||
|
||||
return middleware;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief loads a manifest file
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
exports.loadManifest = function (name) {
|
||||
exports.loadManifest = function (path) {
|
||||
var name;
|
||||
var content;
|
||||
var body;
|
||||
var manifest;
|
||||
var key;
|
||||
|
||||
name = fs.join(path, "manifest.json");
|
||||
content = fs.read(name);
|
||||
body = JSON.parse(content);
|
||||
manifest = JSON.parse(content);
|
||||
|
||||
for (key in body.apps) {
|
||||
if (body.apps.hasOwnProperty(key)) {
|
||||
var app = body.apps[key];
|
||||
for (key in manifest.apps) {
|
||||
if (manifest.apps.hasOwnProperty(key)) {
|
||||
var app = manifest.apps[key];
|
||||
|
||||
console.info("
|
||||
console.info("loading app '%s' from '%s'", key, app);
|
||||
|
||||
module.loadAppScript(path, manifest, app);
|
||||
}
|
||||
}
|
||||
|
||||
return body;
|
||||
};
|
||||
|
||||
// We finish off with exporting FuxxApplication and the middlewares.
|
||||
// Everything else will remain our secret.
|
||||
//
|
||||
// Fin.
|
||||
exports.FuxxApplication = FuxxApplication;
|
||||
exports.BaseMiddleware = BaseMiddleware;
|
||||
exports.FormatMiddleware = FormatMiddleware;
|
||||
|
|
|
@ -192,8 +192,10 @@ sub formatFile ($$$) {
|
|||
$line = "$1";
|
||||
}
|
||||
|
||||
if ($line =~ /^[ \t]*(\/\/ --.*)$/) {
|
||||
$line = "$1";
|
||||
if (0) {
|
||||
if ($line =~ /^[ \t]*(\/\/ --.*)$/) {
|
||||
$line = "$1";
|
||||
}
|
||||
}
|
||||
|
||||
if ($isJavaScript == 0) {
|
||||
|
|
Loading…
Reference in New Issue