mirror of
https://gitlab.silvrtree.co.uk/martind2000/censis-archive.git
synced 2025-02-06 16:09:15 +00:00
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
|
/**
|
||
|
*
|
||
|
* User: Martin Donnelly
|
||
|
* Date: 2016-04-05
|
||
|
* Time: 11:48
|
||
|
*
|
||
|
*/
|
||
|
/*jshint node:true*/
|
||
|
|
||
|
|
||
|
var db = require('../units/db-connector').dbConnection;
|
||
|
var dbPages = require('../units/db-pages')(db);
|
||
|
var logger = require('log4js').getLogger();
|
||
|
|
||
|
module.exports = function(app) {
|
||
|
var express = require('express');
|
||
|
var beaconRouter = express.Router();
|
||
|
|
||
|
beaconRouter.get('/', function(req, res) {
|
||
|
'use strict';
|
||
|
var beacon = {};
|
||
|
|
||
|
logger.debug(req.headers);
|
||
|
console.error(req.headers);
|
||
|
if (req.headers.hasOwnProperty('beacon')) {
|
||
|
beacon = JSON.parse(req.headers.beacon);
|
||
|
logger.debug(beacon);
|
||
|
}
|
||
|
|
||
|
logger.info('gettingLatestAddedPage');
|
||
|
dbPages.getLatestAddedPage()
|
||
|
.then((d) => {
|
||
|
res.redirect(301, d.fullpath);
|
||
|
}).catch((err)=> {
|
||
|
console.error(err);
|
||
|
res.status(401).end();
|
||
|
});
|
||
|
|
||
|
});
|
||
|
|
||
|
app.use('/beacon', require('body-parser').json());
|
||
|
app.use('/beacon', require('body-parser').text());
|
||
|
app.use('/beacon', require('body-parser').urlencoded());
|
||
|
|
||
|
app.use('/beacon', beaconRouter);
|
||
|
};
|