Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 33 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,28 @@ const path = require('path');
const helmet = require('helmet')

const app = express();

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}));

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'));
});

// Handling lowercase order Ids
var orderUppercase = (req, res, next) => {

const orderUppercase = (req, res, next) => {
if (req.params.orderId) {
const orderIdUP = req.params.orderId.toUpperCase()
const orderIdUP = req.params.orderId.toUpperCase()
if (req.params.orderId != orderIdUP) {
res.redirect('/order/' + orderIdUP)
}
else {
} else {
next()
}
}
};

// General handler for the rest of the URLs
var generalHandler = (req, res) => {
const generalHandler = (req, res) => {

let redirectRequired = false;
let params = {};
Expand All @@ -47,7 +37,7 @@ var generalHandler = (req, res) => {

if (req.query.lang && req.query.lang !== req.query.lang.toLowerCase()) {
redirectRequired = true;
req.query.lang = req.query.lang.toLowerCase()
req.query.lang = req.query.lang.toLowerCase()
}

if (redirectRequired) {
Expand All @@ -57,9 +47,33 @@ var generalHandler = (req, res) => {
return;
}

res.sendFile(path.resolve(process.env.NEXCHANGE_ROOT, 'index.html'));
res.sendFile(path.resolve(NEXCHANGE_ROOT, 'index.html'));
};

//Helmet helps you secure your Express apps by setting various HTTP headers.
app.use(helmet());

// ### Assets ###
app.use(express.static(path.resolve(NEXCHANGE_ROOT), {index: false}));
app.use('/blog-asset', express.static(path.resolve(ICO_ROOT, 'blog-asset'), {index: false}));


// ### Blog routes ###
app.get('/blog', (req, res) => {
res.sendFile(path.resolve(ICO_ROOT,'blog/index.html'));
});

app.get('/blog/:slug', function (req, res) {
res.sendFile(path.resolve(ICO_ROOT, 'blog', req.params.slug, 'index.html'));
});

// blog error handler middleware
app.use((error, req, res, next) => {
res.status(error.status || 500).sendFile(path.resolve(ICO_ROOT, '404/index.html'));
});


// ### n.Exchange routes ###
// Convert order ids to uppercase
app.get('/order/:orderId', [orderUppercase, generalHandler]
);
Expand All @@ -71,3 +85,4 @@ app.get('*', generalHandler);
app.listen(3000, () => console.log('Nexchange Frontend Proxy is listening on port 3000!'));