From 93ce36055197721918b18447e9301f2a187297ea Mon Sep 17 00:00:00 2001 From: Kegan Myers Date: Sat, 9 Aug 2014 01:40:38 -0500 Subject: [PATCH] Change how listening port is defined --- README.md | 8 +++++++- app.js | 17 +++++++++++++---- config.json.example | 3 ++- package.json | 3 ++- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 534cfeb..f305202 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,17 @@ slack-command-server ==================== Slack command server is a simple way to build a server that responds to slack slash commands. - +Getting Started +=============== +1. Clone this repository +2. Configure according to the `Configuration` section +3. Configuration ============= Configuring the server is simple, you can use any plugin compatible with [slack-command-router](https://github.com/terribly-lazy/slack-command-router), custom or otherwise. +You must define what port for the app to listen on by defining `port: 80` + To use pre-written plugins write your configuration thusly: ```json { diff --git a/app.js b/app.js index bcd6f79..5dfad2b 100644 --- a/app.js +++ b/app.js @@ -1,10 +1,19 @@ var connect = require('connect'), SlackIncoming = require('slack-command-router'), path = require('path'), - fs = require('fs'); + fs = require('fs'), + _ = require('lodash'); -var config = JSON.parse(fs.readFileSync("config.json")), - slack = new SlackIncoming(); +var config = JSON.parse(fs.readFileSync("config.json")); + +var requiredSetup = ["port"]; +if (_.intersection(_.keys(config), requiredSetup).length !== requiredSetup.length) { + throw { + message: "Missing required configuration parameters" + } +} + +var slack = new SlackIncoming(); var pluginsToInstall = config.plugins || [], pluginsToLoad = config["local-plugins"] || []; @@ -56,7 +65,7 @@ function startApp() { res.writeHead(400); res.end("Unable to handle request"); }); - app.listen(2354); + app.listen(config.port); } installPlugins(initCallback(function() { diff --git a/config.json.example b/config.json.example index ccf3125..b8088d9 100644 --- a/config.json.example +++ b/config.json.example @@ -2,5 +2,6 @@ "plugins": [ "slack-roll-command" ], - "local-plugins": [] + "local-plugins": [], + "port": 80 } \ No newline at end of file diff --git a/package.json b/package.json index 845bc3f..de06607 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "slack-command-server", - "version": "0.0.0", + "version": "0.0.1", "description": "A slack slash command hander framework", "main": "app.js", "scripts": { @@ -20,6 +20,7 @@ "license": "BSD-2-Clause", "dependencies": { "connect": "~3.1.0", + "lodash": "^2.4.1", "npm": "^1.4.23", "require-directory": "~2.0.0", "slack-command-router": "0.0.0"