From f4ed51066f16df24db44c11aa0b2356299d07010 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Sat, 17 Feb 2018 18:33:55 +0100 Subject: Migrate from request to axios --- src/server/routes/getSchedule.js | 18 +++++++----------- src/server/routes/index.js | 7 ++++--- 2 files changed, 11 insertions(+), 14 deletions(-) (limited to 'src/server/routes') diff --git a/src/server/routes/getSchedule.js b/src/server/routes/getSchedule.js index 1734cd8..b98e76a 100644 --- a/src/server/routes/getSchedule.js +++ b/src/server/routes/getSchedule.js @@ -1,11 +1,10 @@ const express = require('express'); const router = express.Router(); -const request = require('request'); -const iconv = require('iconv-lite'); const getScheduleData = require('../lib/schools/hetmml/getScheduleData'); const getURLOfUser = require('../lib/schools/hetmml/getURLOfUser'); +const axios = require('../lib/schools/hetmml/axios'); // copied from http://www.meetingpointmco.nl/Roosters-AL/doc/dagroosters/untisscripts.js, // were using the same code as they do to be sure that we always get the same @@ -45,16 +44,13 @@ router.get('/:type/:value', (req, res, next) => { const url = getURLOfUser(scheduleType, type, index, week); - request(url, { encoding: null }, (err, data) => { - if (err) { + axios.get(url) + .then((response) => { + res.status(response.status).end(response.data); + }) + .catch((err) => { next(err); - return; - } - - const utf8Body = iconv.decode(data.body, 'ISO-8859-1'); - - res.status(data.statusCode).end(utf8Body); - }); + }); }); }); diff --git a/src/server/routes/index.js b/src/server/routes/index.js index af82e1f..78f31f3 100644 --- a/src/server/routes/index.js +++ b/src/server/routes/index.js @@ -27,10 +27,11 @@ router.get(['/', '/s/*', '/t/*', '/r/*', '/c/*'], (req, res) => { dailyScheduleWeeksStr, basisScheduleWeeksStr, }); - }).catch(() => { - console.error('Unable to get user info, emergency redirect!'); - res.render('redirect'); }); + // .catch(() => { + // console.error('Unable to get user info, emergency redirect!'); + // res.render('redirect'); + // }); }); module.exports = router; -- cgit v1.1