Skip to content

Commit

Permalink
Added project
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirko committed Aug 5, 2022
0 parents commit ec6eceb
Show file tree
Hide file tree
Showing 130 changed files with 15,324 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
info:
@echo "make option are:"
@echo " - run-frontend "
@echo " - run-backend "
@echo " - run-db "
@echo " - build-frontend "



init-backend:
cd noSpotify-Backend && npm i && npm run start && cd ..

init-frontend:
cd noSpotify-Frontend && npm i --force && ng serve && cd ..

clear-backend:
cd noSpotify-Backend && rm -R node_modules && npm i && npm run start && cd ..

clear-frontend:
cd noSpotify-Frontend && rm -R node_modules && npm i --force && ng serve && cd ..

build-frontend:
cd noSpotify-Frontend && ng build --aot --prod --output-hashing none && cd ..

run-frontend:
cd noSpotify-Frontend && ng serve && cd ..

run-backend:
cd noSpotify-Backend && npm run start && cd ..

run-db:
docker-compose up -d


4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# NoSpotify
# NoSpotify
# NoSpotify
# NoSpotify
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
mongo-container:
image: mongo:3.4.2
environment:
# provide your credentials here
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=rootPassword
ports:
- "27017:27017"
volumes:
# if you wish to setup additional user accounts specific per DB or with different roles you can use following entry point
- "$PWD/mongo-entrypoint/:/docker-entrypoint-initdb.d/"
# no --auth is needed here as presence of username and password add this option automatically
command: mongod
38 changes: 38 additions & 0 deletions noSpotify-Backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages
typings

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history
11 changes: 11 additions & 0 deletions noSpotify-Backend/_helpers/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const config = require('config.json');
const mongoose = require('mongoose');
const connectionOptions = { useCreateIndex: true, useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false };
mongoose.connect(process.env.MONGODB_URI || config.connectionString, connectionOptions);
mongoose.Promise = global.Promise;

module.exports = {
User: require('../users/user.model'),
Playlist: require('../users/playlist.model')

};
21 changes: 21 additions & 0 deletions noSpotify-Backend/_helpers/error-handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = errorHandler;

function errorHandler(err, req, res, next) {
if (typeof (err) === 'string') {
// custom application error
return res.status(400).json({ message: err });
}

if (err.name === 'ValidationError') {
// mongoose validation error
return res.status(400).json({ message: err.message });
}

if (err.name === 'UnauthorizedError') {
// jwt authentication error
return res.status(401).json({ message: 'Invalid Token' });
}

// default to 500 server error
return res.status(500).json({ message: err.message });
}
32 changes: 32 additions & 0 deletions noSpotify-Backend/_helpers/jwt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const expressJwt = require('express-jwt');
const config = require('config.json');
const userService = require('../users/user.service');

module.exports = jwt;

function jwt() {
const secret = config.secret;
let ok = expressJwt({ secret, algorithms: ['HS256'], isRevoked }).unless({
path: [
// public routes that don't require authentication
'/users/authenticate',
'/users/register',
'/users/getMp3',
'/youtube/*',
{ url: /^\/youtube\/.*/, methods: ['GET'] }
]
});

return ok;
}

async function isRevoked(req, payload, done) {
const user = await userService.getById(payload.sub);

// revoke token if user no longer exists
if (!user) {
return done(null, true);
}

done();
};
7 changes: 7 additions & 0 deletions noSpotify-Backend/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"connectionString": "mongodb://root:rootPassword@localhost:27017/?authSource=admin",
"secret": "$3cr3tSeRver!",
"spotifyEmail":"",
"spotifyPassword":"",
"spotifyAppId":""
}
Loading

0 comments on commit ec6eceb

Please sign in to comment.