Skip to content

Commit

Permalink
Fixes Seneca-CDOT#538 Expose search endpoint via web api
Browse files Browse the repository at this point in the history
  • Loading branch information
c3ho committed Mar 6, 2020
1 parent 9e50064 commit 44f0912
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/backend/web/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ const planet = require('./planet');
const posts = require('./posts');
const stats = require('./stats');
const user = require('./user');
const query = require('./query');

const router = express.Router();

router.use(express.static(path.join(__dirname, '../../../frontend/public')));

router.get('/', (req, res) => {
res.send('hi');
console.log('hi');
});

// Legacy CDOT Planet static assets
router.use('/legacy', express.static(path.join(__dirname, '../planet/static')));

Expand All @@ -27,5 +33,6 @@ router.use('/planet', planet);
router.use('/posts', posts);
router.use('/stats', stats);
router.use('/user', user);
router.use('/query', query);

module.exports = router;
15 changes: 15 additions & 0 deletions src/backend/web/routes/query.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const express = require('express');

const { logger } = require('../../utils/logger');

const router = express.Router();

router.get('/', (req, res) => {
// Github rule, query is more than 256 chars or contains more than 5 operators
// return a validation failed message
if (req.query.q.length > 256 || req.query.q.match(/&& | \|\| | !/g).length > 5) {
res.send('Validation failed');
}
});

module.exports = router;

0 comments on commit 44f0912

Please sign in to comment.