Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 0 additions & 7 deletions env.dist

This file was deleted.

2 changes: 1 addition & 1 deletion src/models/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const Sequelize = require('sequelize');

// only used in the dev environment
// require('../../.env');
require('dotenv').config({ path: '../.env' });
require('dotenv').config({ path: '.env' });

// connect to the db
const sequelize = new Sequelize(process.env.DB_NAME, process.env.DB_USER, process.env.DB_PW, {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = (express) => {
// Route sources

// create or retreave existing short link
router.use('/maumasi.fy/v1.1.1', require('./apiEndPoints/shortenUrl')(express));
router.use('/v1', require('./apiEndPoints/shortenUrl')(express));

// redirect to URL address when short link comes in
router.use('/maumasi.fy', require('./apiEndPoints/keyRedirect')(express));
Expand Down
2 changes: 1 addition & 1 deletion src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const routes = require('./routes');


// require('dotenv').config({ path: '.env' }); // <--------- for running unit tests with mocha
require('dotenv').config({ path: '../.env' }); // <--- for running app
require('dotenv').config({ path: '.env' }); // <--- for running app

const app = express();
const PORT = process.env.PORT || 3000;
Expand Down
38 changes: 7 additions & 31 deletions src/services/serviceRepo/randomKeyMaker.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,21 @@

// const maumasiFyURL = require('../../models/db_crud').table('maumasiFyURL');

// Fine, here's a commnet!
const lengthOfGen = 6;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this number?

// private func that produces a random index of the array arg
var randomIndex = (array) => {
return Math.floor(Math.random() * (array.length));
};

module.exports = () => {
// will bemoce a string of random charSets 5 char long
var randomString = '';

// get today's 'day of the month' date
const today = new Date().getDate();

const charSets = {
upperCase: [],
lowerCase: ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd',
'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm'],
numbers: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0],
};
const strAlphaNum = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

// fill charSets.upperCase with uppercase letters
for (var letter of charSets.lowerCase) {
charSets.upperCase.push(letter.toUpperCase());
var outputString = "";
for(var i=0; i<lengthOfGen; i++){
outputString += strAlphaNum.charAt(Math.floor(Math.random() * strAlphaNum.length));
}

// get a random index
const upperIndex1 = randomIndex(charSets.upperCase);
const lowerIndex1 = randomIndex(charSets.lowerCase);
const upperIndex2 = randomIndex(charSets.upperCase);
const lowerIndex2 = randomIndex(charSets.lowerCase);
const numIndex = randomIndex(charSets.numbers);

// build string
randomString += today;
randomString += charSets.upperCase[upperIndex1];
randomString += charSets.upperCase[upperIndex2];
randomString += charSets.lowerCase[lowerIndex1];
randomString += charSets.lowerCase[lowerIndex2];
randomString += charSets.numbers[numIndex];

// console.log(randomString);
return randomString;
return outputString;
};