This repository has been archived by the owner on Oct 24, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
web.coffee
66 lines (55 loc) · 2.08 KB
/
web.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
###
Module dependencies.
###
async = require("async")
express = require("express")
http = require("http")
path = require("path")
logfmt = require("logfmt")
routes = require("./crm")
salesforce = require("node-salesforce")
app = express()
express.logger.format "method", (req, res) -> req.method.toLowerCase()
express.logger.format "url", (req, res) -> req.url.replace('"', """)
express.logger.format "user-agent", (req, res) -> (req.headers["user-agent"] || "").replace('"', "")
app.configure "development", ->
app.use express.errorHandler()
app.use express.logger("dev")
app.configure 'production', ->
app.use express.logger
buffer: false
format: "ns=\"mc.l2crm\" measure=\"http.:method\" source=\":url\" status=\":status\" elapsed=\":response-time\" from=\":remote-addr\" agent=\":user-agent\""
app.configure ->
app.set "port", process.env.PORT or 3000
app.use express.favicon()
app.use express.methodOverride()
app.use logfmt.bodyParserStream()
app.use express.bodyParser()
app.use app.router
# Connect Routes
app.post "/logs", routes.log_drain
app.get "/", (req, res) -> res.send("NOTHING TO SEE HERE")
reset_auth = express.basicAuth("heroku", process.env.HTTP_PASSWORD)
app.get "/reset", reset_auth, (req, res) ->
sf = new salesforce.Connection()
sf.login process.env.CRM_USERNAME, process.env.CRM_PASSWORD, (err, user) ->
async.parallel
case: (aacb) ->
sf.query "SELECT Id FROM Case", (err, result) ->
async.parallel (result.records.map (record) ->
(acb) ->
sf.sobject("Case").destroy record.Id, acb),
aacb
chatter: (aacb) ->
sf.query "SELECT Id FROM FeedItem", (err, result) ->
async.parallel (result.records.map (record) ->
(acb) ->
sf.sobject("FeedItem").destroy record.Id, acb),
aacb
(err, results) ->
console.log "err", err
console.log "results", results
res.send "ok"
# Listen for Requests
http.createServer(app).listen app.get("port"), ->
console.log "Express server listening on port " + app.get("port")