Created
December 24, 2019 08:09
-
-
Save raihan004/9798fb6cfb2bed5bdafcc3d30ea53308 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.get("/", (req, res) => { | |
const msg = req.flash("success"); | |
console.log("success: "+ msg ); | |
res.render("admin", { | |
title: "admin pages", | |
success: msg | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const path = require("path"); | |
const mongoose = require("mongoose"); | |
const cookieParser = require("cookie-parser"); | |
const session = require('express-session'); | |
const flash = require("connect-flash"); | |
/* init app */ | |
const app = express(); | |
/* init env config */ | |
require('dotenv').config(); | |
const port = process.env.PORT || 3000; | |
// getting-started.js | |
mongoose.connect(process.env.DB, { | |
useNewUrlParser: true, | |
useUnifiedTopology: true | |
}); | |
/* middleware */ | |
app.use(express.json()); | |
app.use(express.urlencoded({ extended: false })); | |
/* express session */ | |
app.use(cookieParser("keyboard cat")); | |
app.use( | |
session({ | |
secret: "keyboard cat", | |
resave: false, | |
saveUninitialized: true, | |
cookie: { secure: true } | |
}) | |
); | |
/* flash message */ | |
app.use(flash()); | |
app.use(function(req, res, next) { | |
res.locals.messages = require("express-messages")(req, res); | |
next(); | |
}); | |
/* route */ | |
const adminPages = require("./route/admin_pages"); | |
app.use("/admin/pages/", adminPages); | |
app.listen(port, () => { | |
console.log(`Server started on ${port}`); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.post( | |
"/login", | |
(req, res) => { | |
req.flash('success','Login successfully'); | |
res.redirect("/admin/pages"); | |
} | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if errors | |
each error in errors | |
div.alert.alert-danger #{error.msg} | |
if message | |
div.alert.alert-warning #{message} | |
if success && success.length > 0 | |
div.alert.alert-success #{success} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment