-
Notifications
You must be signed in to change notification settings - Fork 0
Adds langs to path and redirect to staging if payment method is advcash or payeer #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
punitm0
wants to merge
8
commits into
master
Choose a base branch
from
feat/server-lang-redirect
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3283ab0
Feat:
punitm0 752ea3c
redirect to sapi if payment method is adv or pr
punitm0 8a9a297
redirect to sapi or api based on node env
punitm0 d52e776
add tests
punitm0 a8f1ffc
add sepa payment method and update tests
punitm0 7246175
password token in header
punitm0 be19245
fix url
punitm0 cb0b1f2
fix cookie
punitm0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,73 +1,105 @@ | ||
| const express = require('express'); | ||
| const path = require('path'); | ||
| const helmet = require('helmet') | ||
| const express = require("express"); | ||
| const path = require("path"); | ||
| const helmet = require("helmet"); | ||
| const url = require("url"); | ||
|
|
||
| const app = express(); | ||
| const NEXCHANGE_ROOT = process.env.NEXCHANGE_ROOT | ||
| const ICO_ROOT = process.env.ICO_ROOT | ||
| const NEXCHANGE_ROOT = process.env.NEXCHANGE_ROOT; | ||
| const ICO_ROOT = process.env.ICO_ROOT; | ||
|
|
||
| //Helmet helps you secure your Express apps by setting various HTTP headers. | ||
| app.use(helmet()) | ||
| app.use('/ico', express.static(path.resolve(ICO_ROOT))); | ||
| app.use(express.static(path.resolve(NEXCHANGE_ROOT), {index: false})); | ||
| app.use(helmet()); | ||
| app.use("/ico", express.static(path.resolve(ICO_ROOT))); | ||
| app.use(express.static(path.resolve(NEXCHANGE_ROOT), { index: false })); | ||
|
|
||
| function getCur(qParam) { | ||
| return qParam.toUpperCase().substr(-3); | ||
| return qParam.toUpperCase().substr(-3); | ||
| } | ||
|
|
||
| app.get('/ico', (req, res) => { | ||
| res.sendFile(path.resolve(ICO_ROOT, 'index.html')); | ||
| app.get("/ico", (req, res) => { | ||
| res.sendFile(path.resolve(ICO_ROOT, "index.html")); | ||
| }); | ||
|
|
||
| // Handling lowercase order Ids | ||
| var orderUppercase = (req, res, next) => { | ||
|
|
||
| if (req.params.orderId) { | ||
| const orderIdUP = req.params.orderId.toUpperCase() | ||
| if (req.params.orderId != orderIdUP) { | ||
| res.redirect('/order/' + orderIdUP) | ||
| } | ||
| else { | ||
| next() | ||
| } | ||
| const orderUppercase = (req, res, next) => { | ||
| const orderIdUP = req.params.orderId.toUpperCase(); | ||
| if (req.params.orderId !== orderIdUP) { | ||
| res.redirect(`/${lang}/order/${orderIdUP}`); | ||
| } else { | ||
| next(); | ||
| } | ||
| }; | ||
|
|
||
| // General handler for the rest of the URLs | ||
| var generalHandler = (req, res) => { | ||
| const generalHandler = (req, res) => { | ||
| let host = undefined; | ||
| let urlPath = req.path; | ||
| const langInPath = urlPath.split("/")[1]; | ||
| const langInParam = req.query.lang ? req.query.lang.toLowerCase() : undefined; | ||
| let lang = langInPath || langInParam || "en"; | ||
| const fromCurr = req.query.cur_from; | ||
| const toCurr = req.query.cur_to; | ||
| const validLanguages = ["en", "de", "ru"]; | ||
|
|
||
| let redirectRequired = false; | ||
| let params = {}; | ||
| if (req.query.cur_from && req.query.cur_to) { | ||
|
|
||
| // Dont add language path in url, if its not n.exchange | ||
| if ( | ||
| !req.headers.host.includes("n.exchange") && | ||
| !req.headers.host.includes("localhost") | ||
| ) | ||
| lang = ""; | ||
|
|
||
| if (validLanguages.includes(langInPath)) { | ||
| res.header("Set-Cookie", `i18next=${lang}`); | ||
|
|
||
| urlPath = urlPath.substr(lang.length + 1); | ||
|
|
||
| // If lang is in path then ignore lang in param | ||
| delete req.query["lang"]; | ||
| } | ||
|
|
||
| if (fromCurr && toCurr) { | ||
| const fromCurrType = fromCurr.substr(0, fromCurr.length - 3); | ||
|
|
||
| if (["ADVC", "PR"].includes(fromCurrType)) host = "s.api.n.exchange"; | ||
|
|
||
| console.log(fromCurrType); | ||
| req.query.pair = getCur(toCurr) + getCur(fromCurr); | ||
| delete req.query.cur_from; | ||
| delete req.query.cur_to; | ||
| redirectRequired = true; | ||
| req.query.pair = getCur(req.query.cur_to) + getCur(req.query.cur_from); | ||
| delete req.query['cur_to']; | ||
| delete req.query['cur_from']; | ||
| } | ||
|
|
||
| if (req.query.lang && req.query.lang !== req.query.lang.toLowerCase()) { | ||
| if (req.query.lang && validLanguages.includes(langInParam)) { | ||
| delete req.query["lang"]; | ||
| redirectRequired = true; | ||
| req.query.lang = req.query.lang.toLowerCase() | ||
| } | ||
|
|
||
| if (redirectRequired) { | ||
| params = req.query; | ||
| params = Object.keys(params).map(key => key + '=' + params[key]).join('&'); | ||
| res.redirect(req.path + '?' + params); | ||
| const redirectUrl = url.format({ | ||
| pathname: urlPath === "/" ? `/${lang}` : `/${lang}${urlPath}`, | ||
| query: req.query, | ||
| }); | ||
|
|
||
| if (host) { | ||
| res.redirect(`https://${host}${redirectUrl}`); | ||
| return; | ||
| } | ||
|
|
||
| res.redirect(redirectUrl); | ||
| return; | ||
| } | ||
|
|
||
| res.sendFile(path.resolve(process.env.NEXCHANGE_ROOT, 'index.html')); | ||
| res.sendFile(path.resolve(process.env.NEXCHANGE_ROOT, "index.html")); | ||
| }; | ||
|
|
||
| // Convert order ids to uppercase | ||
| app.get('/order/:orderId', [orderUppercase, generalHandler] | ||
| ); | ||
| app.get("/order/:orderId", [orderUppercase, generalHandler]); | ||
|
|
||
| // For all other cases | ||
| app.get('*', generalHandler); | ||
|
|
||
|
|
||
| app.listen(3000, () => console.log('Nexchange Frontend Proxy is listening on port 3000!')); | ||
|
|
||
| app.get("*", generalHandler); | ||
|
|
||
| app.listen(3000, () => | ||
| console.log("Nexchange Frontend Proxy is listening on port 3000!") | ||
| ); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if some new whitelabels come that use our lang param?
However whitelabels generally do not get traffic from bestchange
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Client side routing will be used
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced it with
const languageRedirect = true;when set to true, language will be added in url path while redirecting