Skip to content
This repository has been archived by the owner on Jan 1, 2023. It is now read-only.

Optiona/api acao headers for development #48

Merged
merged 3 commits into from
Sep 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/.env_tpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ SEQ_LOGGING=false
# Time format
DATE_TIME_FORMAT=YYYY-MM-DD HH:mm

# Security
allowAccessOriginAll=false

# --------------------------------------------------------------------------------
# EMAIL #

Expand Down
14 changes: 12 additions & 2 deletions api/intelligence.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,18 @@ initDb.initDatabase().then(() => {
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true,}));

// helps you secure your Express apps by setting various HTTP headers
app.use(helmet());
if (process.env.allowAccessOriginAll === 'true') {
// allowAccessOriginAll will let any origin client connect to this api
app.use(function(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type, Authorization');
next();
});
} else {
// helps you secure your Express apps by setting various HTTP headers
app.use(helmet());
}

app.use(function (req, res, next) {
logger.log(req.method + req.url, logger.LOG_UNDERSCORE);
Expand Down
3 changes: 2 additions & 1 deletion api/routes/plates.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ async function Plates(router, sequelizeObjects) {

router.post('/get/calendar/events', async (req, res) => {
let output = {events: []};
const days = Number(req.body.days || 90);
const knownPlates = await utils.GetLicensePlates(sequelizeObjects);
if (knownPlates.length > 0) {
const rows = await sequelizeObjects.Data.findAll({
Expand All @@ -21,7 +22,7 @@ async function Plates(router, sequelizeObjects) {
],
where: {
file_create_date: {
[Op.gt]: moment().startOf('day').subtract(90, 'days').utc(true).toISOString(true),
[Op.gt]: moment().startOf('day').subtract(days, 'days').utc(true).toISOString(true),
[Op.lt]: new moment().endOf('day').utc(true).toISOString(true),
},
detection_result: {
Expand Down