From 156f83986c405d6d6f8c22da4f358e0d376c7367 Mon Sep 17 00:00:00 2001 From: Oleg Belousov Date: Wed, 20 Mar 2019 23:45:38 +0200 Subject: [PATCH 1/2] patch/fix-redirects --- index.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 47bf289..6f74528 100644 --- a/index.js +++ b/index.js @@ -5,8 +5,7 @@ const app = express(); app.use('/ico', express.static(path.resolve(__dirname, 'ico'))); -app.use(express.static(path.resolve(__dirname, 'nexchange'))); - +var public = path.join(__dirname, 'nexchange'); function getCur(qParam) { return qParam.toUpperCase().substr(-3); } @@ -15,10 +14,12 @@ app.get('/ico', (req, res) => { res.sendFile(path.resolve(__dirname, 'ico', 'index.html')); }); -app.get('*', (req, res) => { +app.get('/', (req, res) => { + console.log(req.path); let redirectRequired = false; let params = {}; if (req.query.cur_from && req.query.cur_to) { + console.log('cur captured'); redirectRequired = true; req.query.pair = getCur(req.query.cur_to) + getCur(req.query.cur_from); delete req.query['cur_to']; @@ -26,6 +27,7 @@ app.get('*', (req, res) => { } if (req.query.lang && req.query.lang !== req.query.lang.toLowerCase()) { + console.log('lang caputred'); redirectRequired = true; req.query.lang = req.query.lang.toLowerCase() } @@ -41,6 +43,7 @@ app.get('*', (req, res) => { }); -app.listen(3000, () => console.log('Example app listening on port 3000!')); - +app.use(express.static(path.resolve(__dirname, 'nexchange'))); +app.use('*', express.static(public)); +app.listen(3000, () => console.log('Example app listening on port 3000!')); From 0b92ccd284e4f6ecbb026a748598ca707de5d913 Mon Sep 17 00:00:00 2001 From: Oleg Belousov Date: Wed, 20 Mar 2019 23:49:37 +0200 Subject: [PATCH 2/2] Update index.js --- index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/index.js b/index.js index 6f74528..6c6f5b9 100644 --- a/index.js +++ b/index.js @@ -15,11 +15,9 @@ app.get('/ico', (req, res) => { }); app.get('/', (req, res) => { - console.log(req.path); let redirectRequired = false; let params = {}; if (req.query.cur_from && req.query.cur_to) { - console.log('cur captured'); redirectRequired = true; req.query.pair = getCur(req.query.cur_to) + getCur(req.query.cur_from); delete req.query['cur_to']; @@ -27,7 +25,6 @@ app.get('/', (req, res) => { } if (req.query.lang && req.query.lang !== req.query.lang.toLowerCase()) { - console.log('lang caputred'); redirectRequired = true; req.query.lang = req.query.lang.toLowerCase() } @@ -44,6 +41,7 @@ app.get('/', (req, res) => { }); app.use(express.static(path.resolve(__dirname, 'nexchange'))); +// remove below after solving /prices/undefined.png error app.use('*', express.static(public)); app.listen(3000, () => console.log('Example app listening on port 3000!'));