Skip to content
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

Update with latest express in examples/with_express (and SSL) #2

Open
emma-audrey opened this issue May 7, 2020 · 0 comments
Open

Comments

@emma-audrey
Copy link

emma-audrey commented May 7, 2020

In case you are using recent express you'll have to update the package (and app.js)

You'll need to create your own ssl cert ( install OpenSSL if not installed) and create a cert like this :
on linux:
openssl req -nodes -new -x509 -keyout server.key -out server.cert
on win, open a bash and use:
[c:\path to your OpenSSL folder] \openssl.exe req -nodes -new -x509 -keyout server.key -out server.cert .
Once you generated the cert & key, don't forget to put those in your nodejs project (I created a folder named "cert" inside my project for this)

Your new URL will be https://localhost:3000 and that's because Deezer don't use "http" anymore so every time you'll need to authenticate, you'll be redirected to a "https" address

- package.json
{ "name": "deeznode", "version": "1.0.0", "description": "", "main": "deez.js", "dependencies": { "acoustid": "^1.2.1", "bluebird": "^3.5.0", "body-parser": "^1.19.0", "browser-id3-writer": "^3.0.3", "cookie-parser": "^1.4.5", "cookie-session": "^1.4.0", "crypto": "0.0.3", "errorhandler": "^1.5.1", "express": "^4.17.1", "express-session": "^1.17.1", "jade": "^1.11.0", "method-override": "^3.0.0", "morgan": "^1.10.0", "node-deezer": "^0.3.3", "request": "^2.81.0", "request-promise": "^4.2.0", "serve-favicon": "^2.5.0", "util": "^0.10.3" }, "devDependencies": {}, "scripts": { "test": "node deez.js https://www.deezer.com/fr/track/4603408" }, "author": "", "license": "ISC" }

- app.js

var express = require('express'), routes = require('./routes'), deezerApiRoutes = require('./routes/deezer'), middleware = require('./middleware'), https = require('https'), path = require('path'); var cookieParser = require('cookie-parser'); var cookieSession = require('cookie-session'); var methodOverride = require('method-override'); var logger = require('morgan'); var session = require('express-session'); var bodyParser = require('body-parser'); var errorHandler = require('errorhandler'); var fs = require('fs'); var app = express(); console.log(__dirname); app.set('port', process.env.PORT || 3000); app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.use(logger('dev')); app.use(cookieParser()); app.use(cookieSession({secret: 'foo'})); app.use(methodOverride()); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); app.use(express.static(path.join(__dirname, 'public'))); if ('development' == app.get('env')) { app.use(errorHandler()); } app.all('/deezer/*', middleware.checkToken); app.get('/dashboard', middleware.checkToken); app.get('/', routes.index); app.get('/deezerCallback', routes.deezerCallback); app.get('/dashboard', routes.dashboard); app.get('/deezer/:resource/:id?', function (req,res,next) { var resource = req.param('resource'); if (!resource) return res.redirect('/dashboard'); if (!deezerApiRoutes[resource]) return next(); deezerApiRoutes[resource](req,res,next); }); app.get('/deezer/*', function (req, res, next) { deezerApiRoutes.wildcard(req,res,next); }); https.createServer({ key : fs.readFileSync('cert/server.key'), cert: fs.readFileSync('cert/server.cert')} , app).listen(app.get('port'), function() { console.log('Express server listening on port ' + app.get('port')); });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant