-
-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
1,362 additions
and
112 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
example/ | ||
examples/next.js/ | ||
examples/express/node_modules | ||
dist/ |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Express example application using next-iron-session | ||
|
||
This is a small example application generated with the [Express application generator](https://expressjs.com/en/starter/generator.html). | ||
|
||
The tl;dr; on how to use `next-iron-session` with Express is this: | ||
|
||
```js | ||
import { ironSession } from "next-iron-session"; | ||
|
||
const session = ironSession({ | ||
cookieName: "next-iron-session/examples/express", | ||
password: process.env.SECRET_COOKIE_PASSWORD, | ||
cookieOptions: { | ||
secure: process.env.NODE_ENV === "production" ? true : false, | ||
}, | ||
}); | ||
|
||
router.get("/profile", session, async function (req, res) { | ||
// now you can access all of the req.session.* utilities | ||
if (req.session.get("user") === undefined) { | ||
res.redirect("/restricted"); | ||
return; | ||
} | ||
|
||
res.render("profile", { | ||
title: "Profile", | ||
userId: req.session.get("user").id, | ||
}); | ||
}); | ||
``` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
var path = require("path"); | ||
|
||
var createError = require("http-errors"); | ||
var express = require("express"); | ||
var logger = require("morgan"); | ||
|
||
var indexRouter = require("./routes/index"); | ||
var usersRouter = require("./routes/users"); | ||
|
||
var app = express(); | ||
|
||
// view engine setup | ||
app.set("views", path.join(__dirname, "views")); | ||
app.set("view engine", "jade"); | ||
|
||
app.use(logger("dev")); | ||
app.use(express.json()); | ||
app.use(express.urlencoded({ extended: false })); | ||
app.use(express.static(path.join(__dirname, "public"))); | ||
|
||
app.use("/", indexRouter); | ||
app.use("/users", usersRouter); | ||
|
||
// catch 404 and forward to error handler | ||
app.use(function (req, res, next) { | ||
next(createError(404)); | ||
}); | ||
|
||
// error handler | ||
app.use(function (err, req, res) { | ||
// set locals, only providing error in development | ||
res.locals.message = err.message; | ||
res.locals.error = req.app.get("env") === "development" ? err : {}; | ||
|
||
// render the error page | ||
res.status(err.status || 500); | ||
res.render("error"); | ||
}); | ||
|
||
module.exports = app; |
Oops, something went wrong.
7113929
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deployment failed with the following error: