Hello one or two months ago I asked for help on this site and several colleagues offered their time (@schoen, @ rg305, etc)
I was working with windows creating an application entirely with Node.js in which I intend to login from facebook.
Well, after trying it for days, I did not get it, so I decided to switch to Ubuntu.
I have created my application from scratch and reach the point of login with faceebock, which I am not allowed by its new HTTPS policy.
The application is running with Express and I have seen several things but I can not perform the complex operations.
I just want to tell me the steps to follow to get my url (michaelgram.test) through https.
I have to tell you that I am new to this topic, thatâs why I was not able to get it with Windows, I hope to get it now.
I have searched other unsuccessful questions on this site. In my previous question they also show me certbot, but I do not find Ubuntu 18.04 from where I work.
I show you the code, the same as the previous time.
Sorry for the syntax, I must use the translator.
Thank you.
let express = require('express');
let aws = require(âaws-sdkâ);
let multer = require(âmulterâ);
let multerS3 = require(âmulter-s3â);
let ext = require(âfile-extensionâ);
let cookieParser = require(âcookie-parserâ);
let bodyParser = require(âbody-parserâ);
let expressSession = require(âexpress-sessionâ);
let passport = require(âpassportâ);
let michaelgram = require(âmichaelgram-clientâ);
let auth = require(â./authâ)
let config = require(â./configâ);
let port = process.env.PORT || 5050;
let client = michaelgram.createClient(config.client);
let s3 = new aws.S3({
accessKeyId: config.aws.accessKey,
secretAccessKey: config.aws.secretKey
});
let storage = multerS3({
s3: s3,
bucket: âmichaelgramâ,
acl: âpublic-readâ,
metadata: function (req, file, cb) {
cb(null, { fieldName: file.fieldname })
},
key: function (req, file, cb) {
cb(null, +Date.now() + â.â + ext(file.originalname))
}
});
let upload = multer({ storage: storage }).single(âpictureâ);
let app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(expressSession({
secret: config.secret,
resave: false,
saveUninitialized: false
}))
app.use(passport.initialize())
app.use(passport.session())
app.set(âview engineâ, âpugâ);
app.use(express.static(âpublicâ));
passport.use(auth.localStrategy);
passport.use(auth.facebookStrategy);
passport.deserializeUser(auth.deserializeUser);
passport.serializeUser(auth.serializeUser);
app.get(â/â, function (req, res) {
res.render(âindexâ, { title: âMichaelgramâ });
})
app.get(â/signupâ, function (req, res) {
res.render(âindexâ, { title: âMichaelgram - Signupâ });
})
app.post(â/signupâ, function (req, res) {
let user = req.body;
client.saveUser(user, function (err, usr) {
if (err) return res.status(500).send(err.message)
debugger
res.redirect(â/signinâ);
});
});
app.get(â/signinâ, function (req, res) {
res.render(âindexâ, { title: âMichaelgram - Signinâ });
})
app.post(â/loginâ, passport.authenticate(âlocalâ, {
successRedirect: â/â,
failureRedirect: â/signinâ
}));
app.get(â/logoutâ, function (req, res) {
req.logout()
res.redirect(â/â)
});
app.get(â/auth/facebookâ, passport.authenticate(âfacebookâ, { scope: âemailâ }));
app.get(â/auth/facebook/callbackâ, passport.authenticate(âfacebookâ, {
successRedirect: â/â,
failureRedirect: â/signinâ
}));
function ensureAuth(req, res, next) {
if (req.isAuthenticated()) {
return next()
}
res.status(401).send({ error: ânot authenticatedâ })
}
app.get(â/whoamiâ, function (req, res) {
if (req.isAuthenticated()) {
return res.json(req.user)
}
res.json({ auth: false })
})
app.get(â/api/picturesâ, function (req, res, next) {
client.listPictures(function (err, pictures) {
if (err) return res.send([]);
res.send(pictures)
})
})
app.post(â/api/picturesâ, ensureAuth, function (req, res) {
upload(req, res, function (err) {
if (err) {
return res.status(500).send(Error uploading file: ${err.message})
}
let user = req.user
let token = req.user.token
let username = req.user.username
let src = req.file.location
client.savePicture({
src: src,
userId: username,
user: {
username: username,
avatar: user.avatar,
name: user.name
}
}, token, function (err, img) {
if (err) {
return res.status(500).send(err.message)
}
res.send(File uploaded: ${req.file.location}
);
})
})
})
app.get(â/api/user/:usernameâ, (req, res) => {
var username = req.params.username;
client.getUser(username, function (err, user) {
if (err) return res.status(404).send({ error: 'user not found '})
res.send(user)
})
})
app.get(â/:usernameâ, function (req, res) {
res.render(âindexâ, { title: Michaelgram - ${req.params.username} });
})
app.get(â/:username/:idâ, function (req, res) {
res.render(âindexâ, { title: Michaelgram - ${req.params.username} });
})
app.listen(port, function (err) {
if (err) return console.log(âHubo un errorâ), process.exit(1);
console.log(âMichaelgram escuchando en el puerto 5050â);
})