Created
January 31, 2014 16:50
-
-
Save denchistyakov/8736049 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/opt/nodejs/0.10/bin/node | |
var Vow = require("vow"); | |
var promises = require("cocaine/lib/client/methods/promises_shim").Vow(Vow); | |
var methods = require("cocaine/lib/client/methods/promises")(promises); | |
var cocaine = require("cocaine"); | |
var argv = require("optimist").argv; | |
var Worker, handle, http; | |
var port = process.env.PORT || 5000; | |
// Cocaine enviroment | |
if (argv.uuid && argv.app && argv.locator) { | |
Worker = new cocaine.Worker(argv); | |
handle = Worker.getListenHandle("http"); | |
http = cocaine.http; | |
// Local web-server enviroment | |
} else { | |
handle = port; | |
http = require('http'); | |
} | |
require('yandex-printf'); | |
// apefront.tst.ape.yandex.net:10053 | |
// argv.locator | |
var client = new cocaine.Client(['apefront.tst.ape.yandex.net', 10053], methods); | |
var log = client.Logger(argv.app); | |
log.on('error', function(err) { | |
console.log('log connect error', err); | |
}); | |
client.on('error', function(err) { | |
console.log('client connect error', err); | |
}); | |
log.connect(); | |
log.on('connect', function() { | |
log.debug('logging: connected'); | |
var express = require('express'); | |
var app = express(); | |
var server = http.createServer(app); | |
server.listen(handle, function() { | |
console.log("Listening on " + port); | |
}); | |
app.use(express.json()) | |
.use(express.urlencoded()) | |
.use(express.multipart()) | |
.use(express.cookieParser()); | |
var supportLangsList = { | |
'com': ['en', 'ru', 'uk', 'tr', 'fr', 'it', 'ja', 'kk', 'pt', 'pt-br', 'es', 'de', 'zh-Hans', 'zh-Hant'], | |
'com.tr': ['tr'], | |
'ru': ['ru'], | |
'ua': ['ru', 'uk'], | |
'by': ['ru'], | |
'kz': ['ru'], | |
'net': ['ru'] | |
}; | |
app.use(require('./express-patch-req')({ | |
cookies: { | |
Session_id: '2:1390390990.-131.5.4459302.8:1384935755672:1476065482:20.668:1.669:1.0.1.1.0.104852.6239.e964940a1f8597a706a6c39e8ef8e484', | |
my: 'YycCAAE2AQEA' | |
}, | |
headers: { | |
host: 'yandex.ru' | |
} | |
})); | |
// Пока logger нелья получать как остальные сервисы | |
app.use(function(req, res, next) { | |
req.services = req.services || {}; | |
req.services.logger = log; | |
next(); | |
}); | |
app.use(require('express-cocaine-service')({ client: client }, 'geobase', 'uatraits', 'urlfetch', 'langdetect')); | |
app.use(require('./express-domain')); | |
app.use(require('./express-cocaine-uatraits')()); | |
app.use(require('./express-cocaine-blackbox')({ | |
blackbox: 'blackbox-mimino.yandex.net', | |
dbfields: ['userinfo.lang.uid'] | |
})); | |
app.use(require('./express-cocaine-langdetect')({ | |
filter: function(req) { | |
return supportLangsList[req.tld]; | |
} | |
})); | |
var dpsOptions = { | |
app: { | |
languages: ['ru', 'uk', 'be', 'kk', 'en', 'tr', 'fr', 'it', 'ja', 'pt', 'pt-br', 'es', 'de', 'zh-Hans', 'zh-Hant'] | |
}, | |
tanker: { | |
host: 'tanker-api.tools.yandex.net', | |
port: 3000, | |
projectId: 'browser_www', | |
keysetsId: [] | |
}, | |
dps: { | |
host: 'dps-proxy.corba.yandex.net', | |
protocol: 'http', | |
projectId: 'browser_www', | |
imagesFolder: '/i/', | |
version: 'stable', | |
format: 'json', | |
// Вилка диапазона секунд на которые мы кэшируем ответ от DPS | |
cache: { | |
from: 300, | |
to: 360 | |
} | |
} | |
}; | |
app.use(require('./express-cocaine-tanker-i18n')(dpsOptions)); | |
app.use(require('./express-cocaine-dps-images')(dpsOptions, ['thankyou', 'simple', 'zombie'])); | |
app.get('/', function(req, res) { | |
res.write(JSON.stringify(req.uatraits, null, ' ') + '\r\n'); | |
res.write(JSON.stringify(req.regionId, null, ' ') + '\r\n'); | |
res.write(JSON.stringify(req.blackbox, null, ' ') + '\r\n'); | |
res.write(JSON.stringify(req.langdetect, null, ' ') + '\r\n'); | |
res.write(JSON.stringify(req.langlist, null, ' ') + '\r\n'); | |
// res.write(JSON.stringify(req.getCache(), null, ' ') + '\r\n'); | |
res.end(''); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment