Skip to content

Commit

Permalink
Fix #16, add support for Express routes defined on the app
Browse files Browse the repository at this point in the history
  • Loading branch information
mschwager committed Jan 10, 2024
1 parent 5daebbb commit 6617947
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Support for Express routes defined on the app ([#16](https://github.com/mschwager/route-detect/issues/16))

## [0.7.0] - 2023-06-28

### Added
Expand Down
10 changes: 10 additions & 0 deletions routes/rules/express.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ rules:
...
$APP = express.Router(...)
...
- pattern-inside: |
import express from "express";
...
$APP = express(...)
...
- pattern-inside: |
import { Router } from "express";
...
Expand Down Expand Up @@ -86,6 +91,11 @@ rules:
...
$APP = express.Router(...)
...
- pattern-inside: |
import express from "express";
...
$APP = express(...)
...
- pattern-inside: |
import { Router } from "express";
...
Expand Down
15 changes: 15 additions & 0 deletions tests/test_rules/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import passport from 'passport';
function authenticated() {
const router1 = Router()
const router2 = express.Router()
const app = express()

router1.use(passport.initialize());
router1.use(passport.session());

router2.use(passport.initialize());
router2.use(passport.session());

app.use(passport.initialize());
app.use(passport.session());

// ruleid: express-route-authenticated
router1.get('/', (req, res) => {
res.send('GET request to the homepage')
Expand All @@ -32,11 +36,17 @@ function authenticated() {
router2.delete('/', (req, res) => {
res.send('DELETE request to the homepage')
})

// ruleid: express-route-authenticated
app.get('/', (req, res) => {
res.send('hello world')
})
}

function unauthenticated() {
const router1 = Router()
const router2 = express.Router()
const app = express()

// ruleid: express-route-unauthenticated
router1.get('/', (req, res) => {
Expand All @@ -47,4 +57,9 @@ function unauthenticated() {
router2.delete('/', (req, res) => {
res.send('DELETE request to the homepage')
})

// ruleid: express-route-unauthenticated
app.get('/', (req, res) => {
res.send('hello world')
})
}

0 comments on commit 6617947

Please sign in to comment.