Skip to content

Commit 596dcf2

Browse files
committed
Added function to change unicode to string for &
1 parent dc3d0a3 commit 596dcf2

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

server.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
'use strict';
44

5+
function unicodeToChar(text) {
6+
return text.replace(/\\u[\dA-F]{4}/gi,
7+
function (match) {
8+
return String.fromCharCode(parseInt(match.replace(/\\u/g, ''), 16));
9+
});
10+
}
11+
12+
513
/********************************
614
Dependencies
715
********************************/
@@ -46,13 +54,13 @@ if(appEnv.isLocal){
4654
useCreateIndex: true,
4755
useUnifiedTopology: true
4856
};
49-
mongoose.connect(process.env.MONGODB_URL, mongoDbOptions)
57+
mongoose.connect(unicodeToChar(process.env.MONGODB_URL), mongoDbOptions)
5058
.then(res => console.log("Connected to mongodb instance"))
5159
.catch(function (reason) {
5260
console.log('Unable to connect to the mongodb instance. Error: ', reason);
5361
});
5462
sessionDB = process.env.MONGODB_URL;
55-
console.log('Your MongoDB is running at ' + process.env.MONGODB_URL);
63+
console.log('Your MongoDB is running at ' + unicodeToChar(process.env.MONGODB_URL));
5664
}
5765
// Connect to MongoDB Service on IBM Cloud
5866
else if(!appEnv.isLocal) {
@@ -75,7 +83,7 @@ else if(!appEnv.isLocal) {
7583
console.log("Your MongoDB is running at ", mongoDbUrl);
7684
// connect to our database
7785
mongoose.Promise = global.Promise;
78-
mongoose.connect(mongoDbUrl, mongoDbOptions)
86+
mongoose.connect(unicodeToChar(mongoDbUrl), mongoDbOptions)
7987
.then(res => console.log("Connected to mongodb instance."))
8088
.catch(function (reason) {
8189
console.log('Unable to connect to the mongodb instance. Error: ', reason);

0 commit comments

Comments
 (0)