spiduler - crawling service gateway
This commit is contained in:
52
index.js
52
index.js
@@ -13,18 +13,25 @@ var proxy = require('express-http-proxy'),
|
||||
const services = require('./app/services');
|
||||
const adapter = new FileSync(__dirname + '/storage/db.json')
|
||||
const db = low(adapter)
|
||||
db.get('authCodes').value().forEach(codeData => {
|
||||
codeData.expiresDate = function () {
|
||||
var d = new Date();
|
||||
d.setDate(d.getDate() + 2);
|
||||
return d;
|
||||
}();
|
||||
services.authorizationService.saveAuthorizationCode(codeData, function (n, codeData) {
|
||||
// console.log(codeData)
|
||||
})
|
||||
});
|
||||
|
||||
const app = express()
|
||||
app.use(expressLogging(logger));
|
||||
app.listen(port, () => {
|
||||
console.log("Server running on port " + port);
|
||||
});
|
||||
|
||||
|
||||
|
||||
db.get('authCodes').value()
|
||||
.forEach(codeData => {
|
||||
codeData.expiresDate = function () {
|
||||
var d = new Date();
|
||||
d.setDate(d.getDate() + 2);
|
||||
return d;
|
||||
}();
|
||||
services.authorizationService.saveAuthorizationCode(codeData, function (n, codeData) {
|
||||
// console.log(codeData)
|
||||
})
|
||||
});
|
||||
|
||||
var OAuthServer = require('simple-oauth-server'),
|
||||
oauthServer = new OAuthServer(
|
||||
@@ -82,13 +89,6 @@ function heartbeat(request, response) {
|
||||
response.json({ code: updated ? 200 : 400, data: updated });
|
||||
}
|
||||
|
||||
cron.schedule('0 * * * * *', () => {
|
||||
services.flushExpiredTokens(300);
|
||||
});
|
||||
|
||||
|
||||
const app = express()
|
||||
app.use(expressLogging(logger));
|
||||
const proxyFilter = function (req, res) {
|
||||
return req.hostname == hostname ? true : new Promise(function (resolve) {
|
||||
resolve(function () {
|
||||
@@ -111,21 +111,18 @@ const proxyFilter = function (req, res) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
app.use('/api/v1/headless', proxy('127.0.0.1:32101', {
|
||||
app.use('/api/v1/headless', proxy('spiduler-headless:32101', {
|
||||
filter: proxyFilter
|
||||
}));
|
||||
|
||||
app.use('/api/v1/spider', proxy('127.0.0.1:32102', {
|
||||
app.use('/api/v1/spider', proxy('spiduler-spider:32102', {
|
||||
filter: proxyFilter
|
||||
}));
|
||||
|
||||
app.use('/api/v1/spiduler', proxy('127.0.0.1:32103', {
|
||||
app.use('/api/v1/spiduler', proxy('spiduler-schedule:32103', {
|
||||
filter: proxyFilter
|
||||
}));
|
||||
|
||||
|
||||
|
||||
app.get('/oauth/authorize', authorize)
|
||||
|
||||
app.get('/api/v1/oauth/token', grantToken)
|
||||
@@ -133,7 +130,6 @@ app.get('/oauth/token', grantToken)
|
||||
|
||||
app.get('/api/test', apiEndpoint)
|
||||
|
||||
|
||||
|
||||
app.listen(port)
|
||||
console.log('Server starting port ' + port)
|
||||
// cron.schedule('0 * * * * *', () => {
|
||||
// services.flushExpiredTokens(300);
|
||||
// });
|
||||
|
||||
Reference in New Issue
Block a user