This repository has been archived by the owner on Nov 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from trailimage/develop
add requireSSL method
- Loading branch information
Showing
6 changed files
with
30 additions
and
2 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,3 +1,7 @@ | ||
## 4.1.0 | ||
|
||
- Add option to require an SSL connection | ||
|
||
## 4.0.2 | ||
|
||
- Fix unhandled error for missing GPX | ||
|
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { Page, Layout, addTemplateMethods } from './template'; | ||
export { view, Renderer } from './view'; | ||
export { requireSSL } from './require-ssl'; |
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,18 @@ | ||
import { HttpStatus } from '@toba/tools'; | ||
import { Request, Response, NextFunction } from 'express'; | ||
|
||
/** | ||
* Middleware to require an SSL connection. | ||
*/ | ||
export function requireSSL(req: Request, res: Response, next: NextFunction) { | ||
if (req.secure) { | ||
next(); | ||
} else if (req.method == 'GET' || req.method == 'HEAD') { | ||
res.redirect( | ||
HttpStatus.TempRedirect, | ||
'https://' + req.header('Host') + req.originalUrl | ||
); | ||
} else { | ||
res.status(HttpStatus.Forbidden).send('Data must be submitted securely'); | ||
} | ||
} |