-
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.
- Loading branch information
Paul McCafferty
committed
May 17, 2021
1 parent
178c2c3
commit ffc30ed
Showing
39 changed files
with
2,387 additions
and
838 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
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 |
---|---|---|
|
@@ -13,23 +13,39 @@ import cookieParser from 'cookie-parser'; | |
import { connectToDatabase } from './db'; | ||
import { initialiseAuthentication } from '../resources/auth'; | ||
import * as Sentry from '@sentry/node'; | ||
import * as Tracing from '@sentry/tracing'; | ||
import helper from '../resources/utilities/helper.util'; | ||
|
||
require('dotenv').config(); | ||
|
||
if (helper.getEnvironment() !== 'local') { | ||
Sentry.init({ | ||
dsn: 'https://[email protected]/5653683', | ||
environment: helper.getEnvironment(), | ||
}); | ||
} | ||
var app = express(); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/5653683', | ||
environment: helper.getEnvironment(), | ||
integrations: [ | ||
// enable HTTP calls tracing | ||
new Sentry.Integrations.Http({ tracing: true }), | ||
// enable Express.js middleware tracing | ||
new Tracing.Integrations.Express({ | ||
// trace all requests to the default router | ||
app, | ||
}), | ||
], | ||
tracesSampleRate: 1.0, | ||
}); | ||
// RequestHandler creates a separate execution context using domains, so that every | ||
// transaction/span/breadcrumb is attached to its own Hub instance | ||
app.use(Sentry.Handlers.requestHandler()); | ||
// TracingHandler creates a trace for every incoming request | ||
app.use(Sentry.Handlers.tracingHandler()); | ||
app.use(Sentry.Handlers.errorHandler()); | ||
|
||
const Account = require('./account'); | ||
const configuration = require('./configuration'); | ||
|
||
const API_PORT = process.env.PORT || 3001; | ||
const session = require('express-session'); | ||
var app = express(); | ||
app.disable('x-powered-by'); | ||
|
||
configuration.findAccount = Account.findAccount; | ||
|
@@ -213,6 +229,7 @@ app.use('/api/v2/papers', require('../resources/paper/v2/paper.route')); | |
|
||
app.use('/api/v1/counter', require('../resources/tool/counter.route')); | ||
app.use('/api/v1/coursecounter', require('../resources/course/coursecounter.route')); | ||
app.use('/api/v1/collectioncounter', require('../resources/collections/collectioncounter.route')); | ||
|
||
app.use('/api/v1/discourse', require('../resources/discourse/discourse.route')); | ||
|
||
|
@@ -231,6 +248,8 @@ app.use('/api/v1/help', require('../resources/help/help.router')); | |
|
||
app.use('/api/v2/filters', require('../resources/filters/filters.route')); | ||
|
||
app.use('/api/v1/mailchimp', require('../services/mailchimp/mailchimp.route')); | ||
|
||
initialiseAuthentication(app); | ||
|
||
// launch our backend into a port | ||
|
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,21 @@ | ||
import express from 'express'; | ||
import { Collections } from './collections.model'; | ||
const rateLimit = require('express-rate-limit'); | ||
|
||
const router = express.Router(); | ||
|
||
const datasetLimiter = rateLimit({ | ||
windowMs: 60 * 1000, // 1 minute window | ||
max: 50, // start blocking after 50 requests | ||
message: 'Too many calls have been made to this api from this IP, please try again after an hour', | ||
}); | ||
|
||
router.post('/update', datasetLimiter, async (req, res) => { | ||
const { id, counter } = req.body; | ||
Collections.findOneAndUpdate({ id: id }, { counter: counter }, err => { | ||
if (err) return res.json({ success: false, error: err }); | ||
return res.json({ success: true }); | ||
}); | ||
}); | ||
|
||
module.exports = router; |
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
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
Oops, something went wrong.