Browse Source

Merge branch 'pr/58'

Outsider 8 years ago
parent
commit
6c9f89da18
7 changed files with 197 additions and 18 deletions
  1. 31 1
      .gitignore
  2. 31 12
      README.md
  3. 101 0
      azuredeploy.json
  4. 31 5
      bin/www
  5. 2 0
      iisnode.yaml
  6. 1 0
      package.json
  7. BIN
      public/images/bg.jpg

+ 31 - 1
.gitignore

@@ -1 +1,31 @@
-node_modules/
+# Logs
+logs
+*.log
+
+# Runtime data
+pids
+*.pid
+*.seed
+
+# Directory for instrumented libs generated by jscoverage/JSCover
+lib-cov
+
+# Coverage directory used by tools like istanbul
+coverage
+
+# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
+.grunt
+
+# node-waf configuration
+.lock-wscript
+
+# Compiled binary addons (http://nodejs.org/api/addons.html)
+build/Release
+
+# Dependency directory
+# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
+node_modules
+
+
+.env
+.env.*

+ 31 - 12
README.md

@@ -9,20 +9,35 @@ and
 [Socket.io's slack page](http://socket.io/slack/).
 
 [![Deploy to Heroku](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)
+[![Deploy to Azure](http://azuredeploy.net/deploybutton.png)](https://azuredeploy.net/)
 
-## Setting
-fill out `config.js` as your infomation.
+## Settings
 
-* `community`: your community or team name to display on join page.
-* `slackUrl` : your slack team url (ex: socketio.slack.com)
-* `slacktoken` : access token of slack.
-  You can generate it in <https://api.slack.com/web#auth>.
-  **You should generate the token in admin user, not owner.**
-  If you generate the token in owner user, `missing_scope` error will be occurred.
-* `inviteToken`: an optional security measure - if it is set, then that token will be required to get invited.
-* `locale`: application language (currently `en`, `de`, `es`, `fr`, `pt`, `pt-BR`, `zh-CN`, `zh-TW`, `ja` and `ko` available).
+##### Local
 
-  You can test your token via curl:
+Create a file in the root called `.env` with the following key/value pairs. `.env`
+files are added to the `.gitignore`.
+
+- `COMMUNITY_NAME` : Your community or team name to display on join page.
+- `SLACK_URL` : Your slack team url (ex: socketio.slack.com)
+- `SLACK_TOKEN` : Your access token for slack.
+  - You can generate it in <https://api.slack.com/web#auth>.
+  **You should generate the token as an admin user, not owner.**
+  If you generate the token in owner user, a `missing_scope` error may occur.
+- `INVITE_TOKEN`: An optional security measure - if it is set, then that token will be required to get invited.
+- `LOCALE`: Application language (currently `en`, `de`, `es`, `fr`, `pt`, `zh-CN`, `zh-TW`, `ja` and `ko` available).
+
+**Sample**
+
+```
+COMMUNITY_NAME=socketio
+SLACK_URL=socketio.slack.com
+SLACK_TOKEN=ffsdf-5411524512154-16875416847864648976-45641654654654654-444334f43b34566f
+INVITE_TOKEN=abcdefg
+LOCAL=en
+```
+
+You can test your token via curl:
 
   ```shell
    curl -X POST 'https://YOUR-SLACK-TEAM.slack.com/api/users.admin.invite' \
@@ -30,6 +45,10 @@ fill out `config.js` as your infomation.
    --compressed
   ```
 
+##### Heroku / Azure
+
+Add the application settings that are defined above for the local `.env` file.
+
 ## Run
 [Node.js](http://nodejs.org/) is required.
 
@@ -37,7 +56,7 @@ fill out `config.js` as your infomation.
 $ git clone git@github.com:outsideris/slack-invite-automation.git
 $ cd slack-invite-automation
 $ npm install
-$ bin/www
+$ npm start
 ```
 
 You can access <http://localhost:3000> on your web browser.

+ 101 - 0
azuredeploy.json

@@ -0,0 +1,101 @@
+{
+    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
+    "contentVersion": "1.0.0.0",
+    "parameters": {
+        "siteName": {
+            "type": "string"
+        },
+        "hostingPlanName": {
+            "type": "string"
+        },
+        "siteLocation": {
+            "type": "string",
+            "default": "West US"
+        },
+        "sku": {
+            "type": "string",
+            "allowedValues": [
+                "Free",
+                "Shared",
+                "Basic",
+                "Standard"
+            ],
+            "defaultValue": "Free"
+        },
+        "workerSize": {
+            "type": "string",
+            "allowedValues": [
+                "0",
+                "1",
+                "2"
+            ],
+            "defaultValue": "0"
+        },
+        "Slack: Slack team name": {
+          "type": "string"
+        },
+        "Slack: Slack team url": {
+          "type": "string"
+        },
+        "Slack: Slack token": {
+          "type": "string"
+        },
+        "Slack: Required invite token": {
+          "type": "string"
+        }
+    },
+    "variables": {},
+    "resources": [
+      {
+        "apiVersion": "2014-06-01",
+        "name": "[parameters('hostingPlanName')]",
+        "type": "Microsoft.Web/serverFarms",
+        "location": "[parameters('siteLocation')]",
+        "properties": {
+            "name": "[parameters('hostingPlanName')]",
+            "sku": "[parameters('sku')]",
+            "workerSize": "[parameters('workerSize')]",
+            "numberOfWorkers": 1
+        }
+      },
+      {
+        "type": "Microsoft.Web/sites",
+        "name": "[parameters('siteName')]",
+        "apiVersion": "2015-08-01",
+        "location": "[parameters('siteLocation')]",
+        "tags": {
+            "[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]": "empty"
+        },
+        "dependsOn": [
+            "[concat('Microsoft.Web/serverFarms/', parameters('hostingPlanName'))]"
+        ],
+        "properties": {
+          "name": "[parameters('siteName')]",
+          "serverFarm": "[parameters('hostingPlanName')]"
+        },
+        "resources": [{
+          "apiVersion": "2014-04-01",
+          "type": "config",
+          "name": "web",
+          "dependsOn": [
+              "[concat('Microsoft.Web/Sites/', parameters('siteName'))]"
+          ],
+          "properties": {
+              "appSettings": [{
+                  "name": "COMMUNITY_NAME",
+                  "value": "[parameters('Slack: Slack team name')]"
+              }, {
+                  "name": "SLACK_URL",
+                  "value": "[parameters('Slack: Slack team url')]"
+              }, {
+                  "name": "SLACK_TOKEN",
+                  "value": "[parameters('Slack: Slack token')]"
+              }, {
+                  "name": "INVITE_TOKEN",
+                  "value": "[parameters('Slack: Required invite token')]"
+              }]
+          }
+      }]
+    }
+  ]
+}

+ 31 - 5
bin/www

@@ -1,18 +1,44 @@
 #!/usr/bin/env node
 
-/**
- * Module dependencies.
- */
+// support for .env file to get loaded in to environment variables.
+var path = require('path');
+var fs = require('fs');
+var envFile = path.join(__dirname, '../.env');
+try {
+  fs.accessSync(envFile, fs.F_OK);
+  require('dotenv').config({path: envFile});
+} catch (e) {
+  // no env file
+}
 
+/**
+* Module dependencies.
+*/
 var app = require('../app');
 var debug = require('debug')('slack-invite-automation:server');
 var http = require('http');
 
+/**
+ * Normalize a port into a number, string, or false.
+ * @param {int} val
+ */
+function normalizePort(val) {
+    var port = parseInt(val, 10);
+    if (isNaN(port)) {
+        return val;
+    } else if (port >= 0) {
+        return port;
+    }
+
+    return false;
+}
+
+
 /**
  * Get port from environment and store in Express.
  */
 
-var port = parseInt(process.env.PORT, 10) || 3000;
+var port = normalizePort(process.env.PORT || '3000');
 app.set('port', port);
 
 /**
@@ -25,7 +51,7 @@ var server = http.createServer(app);
  * Listen on provided port, on all network interfaces.
  */
 
-server.listen(port, '0.0.0.0');
+server.listen(port);
 server.on('error', onError);
 server.on('listening', onListening);
 

+ 2 - 0
iisnode.yaml

@@ -0,0 +1,2 @@
+loggingEnabled: true
+logDirectory: iisnode

+ 1 - 0
package.json

@@ -9,6 +9,7 @@
     "body-parser": "^1.14.0",
     "cookie-parser": "^1.4.0",
     "debug": "^2.2.0",
+    "dotenv": "^2.0.0",
     "express": "^4.13.0",
     "i18n": "^0.7.0",
     "jade": "^1.11.0",

BIN
public/images/bg.jpg