diff --git a/package.json b/package.json index a96f4b86e..861af9a84 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "client-sessions": "^0.8.0", "dotenv": "^5.0.1", "express": "^4.16.2", + "express-hbs": "^1.0.4", "hbs": "^4.0.1", "nodemailer": "^4.6.0", "pg": "^7.4.1", diff --git a/routes/home.js b/routes/home.js new file mode 100644 index 000000000..4d6b65659 --- /dev/null +++ b/routes/home.js @@ -0,0 +1,28 @@ +"use strict"; + +const AppConstants = require("../app-constants"); + +const express = require("express"); +const router = express.Router(); + +const models = require("../db/models"); + +router.get("/", (req, res) => { + res.render("home", { + title: "Firefox Breach Alerts", + }); +}); + +router.post("/scan", (req, res) => { + // const email = req.body.email + // breachedHash = models.BreachedHash.get({ where: { hash: sha1(email) } }) + // breaches = models.Breaches.findAll({ where: {id: [breach1ID, breach2ID, ...] } }) + // res.render("scan", { + // title: "Firefox Breach Alerts: Scan Results", + // email: email, + // breaches: breaches + // }); + res.render("scan"); +}); + +module.exports = router; diff --git a/server.js b/server.js index cf7fa87d6..4c5fb1bad 100644 --- a/server.js +++ b/server.js @@ -4,16 +4,23 @@ const AppConstants = require("./app-constants"); const bodyParser = require("body-parser"); const express = require("express"); +const hbs = require("express-hbs"); const sessions = require("client-sessions"); const EmailUtils = require("./email-utils"); -const OAuthRoute = require("./routes/oauth"); -const UserRoute = require("./routes/user"); +const BaseRoutes = require("./routes/home"); +const OAuthRoutes = require("./routes/oauth"); +const UserRoutes = require("./routes/user"); const app = express(); app.use(bodyParser.json()); app.use(express.static("public")); + +app.engine("hbs", hbs.express4({ + layoutsDir: __dirname + "/views/layouts" +})); app.set("view engine", "hbs"); +app.set("views", __dirname + "/views"); app.use(sessions({ cookieName: "session", @@ -22,12 +29,9 @@ app.use(sessions({ activeDuration: 5 * 60 * 1000, // 5 minutes })); -app.get("/", (req, res) => { - res.render("home"); -}); - -app.use("/oauth", OAuthRoute); -app.use("/user", UserRoute); +app.use("/", BaseRoutes); +app.use("/oauth", OAuthRoutes); +app.use("/user", UserRoutes); EmailUtils.init().then(() => { const listener = app.listen(AppConstants.PORT, () => { diff --git a/views/home.hbs b/views/home.hbs index 4fefb4cef..f1f234713 100644 --- a/views/home.hbs +++ b/views/home.hbs @@ -1,16 +1,4 @@ - - -
- - -