Skip to content

Commit

Permalink
started to update all the backend packages as well
Browse files Browse the repository at this point in the history
  • Loading branch information
snollygolly committed Oct 24, 2017
1 parent 7746436 commit 4fcbfa1
Show file tree
Hide file tree
Showing 9 changed files with 4,673 additions and 61 deletions.
10 changes: 3 additions & 7 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@
"mocha": true
},

"ecmaFeatures": {
"generators": true,
"blockBindings": true,
"templateStrings": true,
"arrowFunctions": true,
"forOf": true,
"parserOptions": {
"ecmaVersion": 8
},

"rules": {
Expand Down Expand Up @@ -45,7 +41,7 @@
"no-var": 2,
"prefer-const": 1,
"prefer-template": 1,
"require-yield": 1,
"require-await": 1,
"arrow-spacing": 2,
"generator-star-spacing": [2, "after"],
"no-confusing-arrow": 2,
Expand Down
27 changes: 15 additions & 12 deletions controllers/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,28 @@ const config = require("../config.json");

let user = null;

module.exports.login = function* login() {
if (this.isAuthenticated()) {
user = this.session.passport.user;
module.exports.login = async(ctx) => {
if (ctx.isAuthenticated()) {
user = ctx.session.passport.user;
}
yield this.render("login", {
await ctx.render("login", {
user: user
});
};

module.exports.logout = function* logout() {
this.logout();
yield this.redirect("/");
module.exports.logout = async(ctx) => {
ctx.logout();
await ctx.redirect("/");
};

module.exports.index = function* index() {
if (this.isAuthenticated()) {
user = this.session.passport.user;
module.exports.index = async(ctx) => {
if (ctx.isAuthenticated()) {
user = ctx.session.passport.user;
} else {
return this.redirect("/");
return ctx.redirect("/");
}
yield this.render("account", {title: config.site.name, user: JSON.stringify(user, null, 2)});
await ctx.render("account", {
title: config.site.name,
user: JSON.stringify(user, null, 2)
});
};
8 changes: 4 additions & 4 deletions controllers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ const config = require("../config.json");

let user = null;

module.exports.index = function* index() {
if (this.isAuthenticated()) {
user = this.session.passport.user;
module.exports.index = async(ctx) => {
if (ctx.isAuthenticated()) {
user = ctx.session.passport.user;
}
yield this.render("index", {
await ctx.render("index", {
title: config.site.name,
user: user
});
Expand Down
22 changes: 11 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

const config = require("./config.json");

const koa = require("koa");
const Koa = require("koa");
const hbs = require("koa-hbs");
const serve = require("koa-static-folder");
const serve = require("koa-static");
const mount = require("koa-mount");

// for passport support
const session = require("koa-generic-session");
const session = require("koa-session");
const bodyParser = require("koa-bodyparser");
const passport = require("koa-passport");

const app = koa();
const app = new Koa();

exports.app = app;
exports.passport = passport;
Expand All @@ -27,7 +28,7 @@ app.proxy = true;

// sessions
app.keys = [config.site.secret];
app.use(session());
app.use(session(app));

// body parser
app.use(bodyParser());
Expand All @@ -37,29 +38,28 @@ app.use(passport.initialize());
app.use(passport.session());

// statically serve assets
app.use(serve("./assets"));
app.use(mount("/assets", serve("./assets")));

// load up the handlebars middlewear
app.use(hbs.middleware({

viewPath: `${__dirname}/views`,
layoutsPath: `${__dirname}/views/layouts`,
partialsPath: `${__dirname}/views/partials`,
defaultLayout: "main"
}));

app.use(function* error(next) {
require("./routes");

app.use(async(next) => {
try {
yield next;
await next;
} catch (err) {
this.status = err.status || 500;
this.body = err.message;
this.app.emit("error", err, this);
}
});

require("./routes");

console.log(`${config.site.name} is now listening on port ${config.site.port}`);
app.listen(config.site.port);

Expand Down
10 changes: 1 addition & 9 deletions models/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const passport = require("../index.js").passport;
const config = require("../config.json");
const co = require("co");

passport.serializeUser((user, done) => {
done(null, user);
Expand All @@ -24,12 +23,5 @@ passport.use(new GithubStrategy({
callbackURL: `${config.site.oauth.host}${port}/auth/github/callback`
}, (token, tokenSecret, profile, done) => {
// retrieve user ...
co(function* auth() {
// do some async/yield stuff here to get/set profile data
done(null, profile);
}).catch(function onError(e) {
console.error("Something went terribly wrong!");
console.error(e.stack);
done(e, null);
});
done(null, profile);
}));
Loading

0 comments on commit 4fcbfa1

Please sign in to comment.