summaryrefslogtreecommitdiff
path: root/examples/lib/okexample
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2016-04-14 14:14:34 -0400
committerJules Laplace <jules@okfoc.us>2016-04-14 14:14:34 -0400
commitfa343212514f1e6f975e5cf5957e440555afb815 (patch)
tree18ec4adc898f79e4c3262e4d12861ea212837f69 /examples/lib/okexample
parent099c4091f1e98148e5ac05d1fc30cfd8333707bb (diff)
example services
Diffstat (limited to 'examples/lib/okexample')
-rw-r--r--examples/lib/okexample/index.js48
-rw-r--r--examples/lib/okexample/package.json11
2 files changed, 59 insertions, 0 deletions
diff --git a/examples/lib/okexample/index.js b/examples/lib/okexample/index.js
new file mode 100644
index 0000000..b614697
--- /dev/null
+++ b/examples/lib/okexample/index.js
@@ -0,0 +1,48 @@
+
+/**
+ * Example service to show how these things should be set up.
+ *
+ * Services should be added to index.js in the proper area,
+ * with any configuration parameters that you want passed in:
+ *
+ * services: {
+ * example: {
+ * lib: require("./lib/okexample"),
+ * stuff: "things",
+ * }
+ * },
+ *
+ * The service will be mounted on /_services/example
+ *
+ * This binds to route '*' but you can specify e.g. "/thing",
+ * and it will be mounted on /_services/example/thing
+ */
+
+function OKExample (options) {
+ if (!(this instanceof OKExample)) return new OKExample(options)
+ options = options || {}
+ if (!options.express)
+ throw new Error('Express not provided to OKDumpfm');
+ if (!options.config)
+ throw new Error('Configuration not provided to OKDumpfm');
+
+ var express = options.express
+ var router = express.Router()
+ var config = options.config
+
+ router.get('*', function (req, res) {
+ res.send(config.stuff)
+ })
+
+ router.post('*', function (req, res) {
+ throw new Error('OKExample POST requests not implemented')
+ })
+
+ this._router = router
+}
+
+OKExample.prototype.middleware = function () {
+ return this._router
+}
+
+module.exports = OKExample
diff --git a/examples/lib/okexample/package.json b/examples/lib/okexample/package.json
new file mode 100644
index 0000000..2b2a47c
--- /dev/null
+++ b/examples/lib/okexample/package.json
@@ -0,0 +1,11 @@
+{
+ "name": "okexample",
+ "version": "1.0.0",
+ "description": "example service",
+ "main": "index.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "author": "okfocus <frontdesk@okfoc.us>",
+ "license": "LNT"
+}