Resolve username from opt board id
parent
ee1bdba661
commit
631eaff9f7
|
@ -15,6 +15,7 @@ module.exports = {
|
|||
request: rootRoute + '/request',
|
||||
signatures: '/signatures',
|
||||
signUp: rootRoute + '/authenticate/signup',
|
||||
slotting: rootRoute + '/slotting',
|
||||
squads: rootRoute + '/squads',
|
||||
users: rootRoute + '/users',
|
||||
wars: rootRoute + '/wars',
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -21,23 +21,24 @@
|
|||
"dependencies": {
|
||||
"async": "^2.5.0",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"body-parser": "~1.13.2",
|
||||
"body-parser": "^1.18.3",
|
||||
"cors": "^2.8.4",
|
||||
"cron": "^1.3.0",
|
||||
"cron": "^1.4.1",
|
||||
"debug": "^3.1.0",
|
||||
"express": "^4.16.2",
|
||||
"express": "^4.16.4",
|
||||
"imagemin": "^5.2.2",
|
||||
"imagemin-pngquant": "^5.0.0",
|
||||
"jimp": "^0.2.27",
|
||||
"jsonwebtoken": "^7.4.3",
|
||||
"jimp": "^0.5.4",
|
||||
"jsonwebtoken": "^8.3.0",
|
||||
"lodash": "^4.17.4",
|
||||
"mkdirp": "^0.5.1",
|
||||
"mongoose": "^5.0.3",
|
||||
"morgan": "~1.6.1",
|
||||
"morgan": "^1.9.1",
|
||||
"multer": "^1.3.0",
|
||||
"node-html-parser": "^1.1.10",
|
||||
"node-sha1": "^1.0.1",
|
||||
"q": "^1.5.0",
|
||||
"serve-favicon": "~2.3.0",
|
||||
"serve-favicon": "^2.5.0",
|
||||
"supports-color": "^5.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -48,8 +49,8 @@
|
|||
"eslint": "^4.18.2",
|
||||
"eslint-config-google": "^0.9.1",
|
||||
"hercule": "^4.1.1",
|
||||
"mocha": "^3.5.3",
|
||||
"mongodb-memory-server": "^1.7.3",
|
||||
"mocha": "^5.2.0",
|
||||
"mongodb-memory-server": "^2.6.0",
|
||||
"nodemon": "^1.14.12"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
'use strict';
|
||||
|
||||
// modules
|
||||
const express = require('express');
|
||||
const http = require("http");
|
||||
const https = require("https");
|
||||
const parse = require('node-html-parser').parse;
|
||||
|
||||
// HTTP status codes by name
|
||||
const codes = require('./http-codes');
|
||||
|
||||
const routerHandling = require('../middleware/router-handling');
|
||||
|
||||
/**
|
||||
* getHtml: REST get request returning HTML page response
|
||||
* @param options: http options object
|
||||
* @param onResult: callback to pass the results JSON object(s) back
|
||||
*/
|
||||
const getHtml = (options, onResult) => {
|
||||
let port = (options.port === 443) ? https : http;
|
||||
let req = port.request(options, (res) => {
|
||||
var output = '';
|
||||
console.log(options.host + ':' + res.statusCode);
|
||||
res.setEncoding('utf8');
|
||||
|
||||
res.on('data', function (chunk) {
|
||||
output += chunk;
|
||||
});
|
||||
|
||||
res.on('end', function() {
|
||||
if (res.statusCode === 301) { // follow redirect
|
||||
const location = res.headers.location;
|
||||
const baseUrl = ((options.port === 443) ? 'https':'http') + '://' + options.host;
|
||||
options.path = location.replace(baseUrl, '');
|
||||
getHtml(options, (status, redirectData) => {
|
||||
onResult(status, redirectData);
|
||||
})
|
||||
} else {
|
||||
onResult(res.statusCode, output);
|
||||
}
|
||||
});
|
||||
});
|
||||
req.end();
|
||||
};
|
||||
|
||||
const defaulUserReqOptions = {
|
||||
host: 'opt4.net',
|
||||
port: 443,
|
||||
path: '/dashboard/index.php?user/',
|
||||
method: 'GET'
|
||||
};
|
||||
|
||||
const slotting = new express.Router();
|
||||
|
||||
// routes **********************
|
||||
slotting.route('/user/:id')
|
||||
.get((req, res, next) => {
|
||||
const userId = req.params.id;
|
||||
const options = Object.assign({}, defaulUserReqOptions);
|
||||
options.path = options.path.concat(userId);
|
||||
|
||||
getHtml(options, (status, targetRes) => {
|
||||
if (status !== codes.success) {
|
||||
const err = new Error('Can not resolve user from remote service');
|
||||
err.status = codes.notfound;
|
||||
return next(err);
|
||||
}
|
||||
|
||||
const root = parse(targetRes);
|
||||
const userNameEl = root.querySelector('.contentTitle');
|
||||
let user = {
|
||||
name: userNameEl.childNodes[0].rawText.trim()
|
||||
};
|
||||
|
||||
res.locals.items = user;
|
||||
res.locals.processed = true;
|
||||
return next();
|
||||
});
|
||||
})
|
||||
|
||||
.all(
|
||||
routerHandling.httpMethodNotAllowed
|
||||
);
|
||||
|
||||
// this middleware function can be used, if you like or remove it
|
||||
// it looks for object(s) in res.locals.items and if they exist, they are send to the client as json
|
||||
slotting.use(routerHandling.emptyResponse);
|
||||
|
||||
module.exports = slotting;
|
|
@ -48,6 +48,7 @@ const commandRouter = require('./routes/command');
|
|||
const campaignRouter = require('./routes/campaigns');
|
||||
const warRouter = require('./routes/wars');
|
||||
const logRouter = require('./routes/logs');
|
||||
const slottingRouter = require('./routes/slotting');
|
||||
|
||||
// Configuration ***********************************
|
||||
// mongoose promise setup
|
||||
|
@ -98,6 +99,7 @@ app.use(urls.wars, warRouter);
|
|||
app.use(urls.players, playerRouter);
|
||||
app.use(urls.campaigns, campaignRouter);
|
||||
app.use(urls.logs, logRouter);
|
||||
app.use(urls.slotting, slottingRouter);
|
||||
app.use(urls.command, apiAuthenticationMiddleware, checkAdmin, commandRouter);
|
||||
app.use(urls.account, apiAuthenticationMiddleware, checkAdmin, accountRouter);
|
||||
|
||||
|
|
Loading…
Reference in New Issue