Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
* origin/dev:
  Use an environment variable to specify the ABE API URL
  Fix a couple of console.log message typos
  Add eslint and fix some lint errors
  Update package.json description
  • Loading branch information
osteele committed Apr 19, 2018
2 parents e2a6f38 + cfdd161 commit 7382aa4
Show file tree
Hide file tree
Showing 16 changed files with 2,245 additions and 49 deletions.
35 changes: 35 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
env:
browser: true

parserOptions:
ecmaVersion: 6

extends:
- eslint:recommended

# see https://eslint.org/docs/user-guide/configuring#specifying-globals
globals:
# $: false
# moment: false # TODO: use `import` to import this, and remove this exception
# global: false
# module: false
db: false
process: false # for webpack process.env variables

rules:
no-console: warn
no-unused-vars: [error, { argsIgnorePattern: "^_" }]
no-useless-escape: warn # TODO: remove (so this is an error)

# Server-side:
overrides:
files: [ "*.js", "models/*.js", "routes/*.js", "scripts/*.js" ]
env:
browser: false
node: true
globals:
Promise: false
module: false
require: false
rules:
no-console: off
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ export MONGODB_URI="<Get this from mLab instance>";

Optionally set the `ADMIN_PASSWORD` to something. If you do not set it, then there will be no auth on the admin page.

By default, the app uses the staging instance of ABE. In the future, this will
only be accessible with authentication, or from within the Olin LAN. To use a
local ABE instance:

1. Follow the instructions [here](https://github.com/olinlibrary/ABE#readme) to
run the local ABE server.
2. Set the `ABE_API_URI` environment variable to `http://localhost:3000`.

Once you've set these environment variables, you should be able to run the app locally by executing `sudo -E npm start` (which runs `node server.js` as specified in `package.json`) from the root of the repo directory. The `-E` flag allows us to use the above environment variables when running with sudo permissions. This will serve the app at [http://localhost:80](http://localhost).

NOTE: You'll need to [add these as environment variables to your Heroku instance](https://devcenter.heroku.com/articles/heroku-local#set-up-your-local-environment-variables) as well. Depending on your setup, you may want to have a separate database for local vs. production, but for just getting the app running it's not a crime to use the same.
Expand Down Expand Up @@ -109,6 +117,8 @@ mongorestore --drop -d $3 mLabDump/heroku_w45g6cd6;
## Contributing
To contribute, fork this repo and clone it to your local development environment. When making edits, make sure to base off of the `dev` branch by first running `git checkout dev` and ensuring that it's up to date with this repo `git pull upstream dev`. Once you're up to date, create a new branch off `dev` with `git checkout -b <branch_name>` and make any edits you'd like to make.

Run `npm run lint` to verify your code formatting.

Once you've made the changes you'd like to make, ensure that they are committed to your new branch before switching back to dev to make sure it's fully up to date (another `git checkout dev` and `git pull upstream dev`). Once this is done, switch back to your branch (`git checkout <branch_name>`) and rebase onto dev with `git rebase -i dev`. This will ensure that any changes that have been made to `dev` are accounted for in your branch, thus avoiding any merge conflicts when we try to pull those changes into the main repo. To learn more about rebasing, look [here](https://help.github.com/articles/about-git-rebase/). If you've pushed your branch up to your version of the repo before rebasing, you will need to force push your rebased changes to your branch to ensure that the correct history is included for merging.

After all of that, go ahead and open a new pull request onto the upstream version of dev! This pull request should have a title describing the changes at a very high level and a description that gets into more details. These details should include what changes have been made and why. Then request that a contributor on the main repo review your code. Once suggestions have been made, make necessary edits and confirm once again that everything looks good. If yes, your reviewer can go ahead and merge it in!
Expand All @@ -122,12 +132,12 @@ Set environment variables for AWS:
`ACCESS_KEY_ID
SECRET_ACCESS_KEY`

Once you've setup your own version of the app, run `sudo -E nodejs server.js` to get it running.
Once you've setup your own version of the app, run `sudo -E **nodejs server.**js` to get it running.


## For Frontend, templates, css:

To test each component of the template, I recommend that
To test each component of the template, I recommend that

## Directory Structure
![#f03c15](https://placehold.it/15/f03c15/000000?text=+) `Backend`
Expand Down
19 changes: 10 additions & 9 deletions models/bob.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ const BobModel = mongoose.model('Bob', bobSchema);
@param {Object[]} bobData
*/
function saveBob(bobData) {
let mediaStatus = "";
if (bobData.data.Link) {
mediaStatus = false;
} else {
console.log("Warning: Saving bob without Link");
mediaStatus = true;
}
// TODO: use mediaStatus, or remove this code
// let mediaStatus = "";
// if (bobData.data.Link) {
// mediaStatus = false;
// } else {
// console.log("Warning: Saving bob without Link");
// mediaStatus = true;
// }

const newBob = new BobModel({
data: bobData.data,
Expand All @@ -53,7 +54,7 @@ function saveBob(bobData) {
* @param {String} url
*/
function checkMediaStatus(url) {
request.head(url, function (err, res, body) {
request.head(url, function (err, res, _body) {
if (err){ console.log(err); }
if (res.statusCode === 200) {
setMediaStatus(url, true);
Expand Down Expand Up @@ -158,7 +159,7 @@ function flagBob(bobId) {
*/
function setMediaStatus(mediaURL, status=true) {
console.log("looking for bob with..:" + mediaURL);
data = BobModel.findOneAndUpdate({ data : { Link: mediaURL }}, { mediaReady: status }).lean();
const data = BobModel.findOneAndUpdate({ data : { Link: mediaURL }}, { mediaReady: status }).lean();
console.log("Setting : " + data);
return data;
}
Expand Down
2 changes: 1 addition & 1 deletion models/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ function connectToDB(url) {
db.on('error', console.error.bind(console, 'mongoose connection error:'));

db.once('open', function(){
console.log("Connected to mongodb (Note: deprication warning above is a bug)");
console.log("Connected to mongodb (Note: deprecation warning above is a bug)");
});
}
49 changes: 26 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
{
"name": "forwardboard",
"version": "1.0.0",
"description": "FORWARDboard server ===",
"main": "server.js",
"dependencies": {
"aws-sdk": "^2.87.0",
"body-parser": "^1.17.2",
"express": "^4.15.3",
"express-sslify": "1.2.0",
"mongoose": "^4.10.6",
"package.json": "^2.0.1",
"promise": "^7.1.1",
"request": "^2.81.0",
"serve-favicon": "^2.4.5",
"socket.io": "^2.0.3"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "",
"license": "ISC"
"name": "FUTUREboard",
"version": "1.0.0",
"description": "FUTUREboard digital signage platform",
"main": "server.js",
"dependencies": {
"aws-sdk": "^2.87.0",
"body-parser": "^1.17.2",
"express": "^4.15.3",
"express-sslify": "1.2.0",
"mongoose": "^4.10.6",
"package.json": "^2.0.1",
"promise": "^7.1.1",
"request": "^2.81.0",
"serve-favicon": "^2.4.5",
"socket.io": "^2.0.3"
},
"devDependencies": {
"eslint": "^4.19.1"
},
"scripts": {
"lint": "eslint --cache *.js lambda models routes scripts",
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "",
"license": "ISC"
}
4 changes: 2 additions & 2 deletions routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = function(io, db) {
* Currently only checks for req.headers.auth, in the future it will use a more robust authentication method
*/

adminPassword = process.env.ADMIN_PASSWORD;
const adminPassword = process.env.ADMIN_PASSWORD;
function ensureAuthenticated(req, res, next) {
if (req.headers.auth === adminPassword | req.query.auth === adminPassword){
next();
Expand Down Expand Up @@ -93,7 +93,7 @@ module.exports = function(io, db) {
});
}

function POSTcreateNewBob(req, res, next) {
function POSTcreateNewBob(req, res, _next) {
if (!req.body.endDate){
req.body.endDate = Date.now() + 2 * 60 * 60 * 12; // Default to two days
}
Expand Down
6 changes: 3 additions & 3 deletions routes/awsapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ var router = express.Router();


/*
set envirnoment variables: ACCESS_KEY_ID, SECRET_ACCESS_KEY
set environment variables: ACCESS_KEY_ID, SECRET_ACCESS_KEY
*/

const S3_BUCKET = "upload.media.futureboard.olin.build"; // resized bucket
const ACCESS_KEY_ID = process.env.ACCESS_KEY_ID;
const SECRET_ACCESS_KEY = process.env.SECRET_ACCESS_KEY;

if (ACCESS_KEY_ID == null || SECRET_ACCESS_KEY == null){
console.log("ERROR: s3 envirnoment variables not set!");
console.log("ERROR: s3 environment variables not set!");
}

aws.config.update({
Expand Down Expand Up @@ -108,7 +108,7 @@ module.exports = function (io, db) {
// If it is a subscription confirmation, get the page
if (req.headers['x-amz-sns-message-type'] === 'SubscriptionConfirmation') {
console.log("SNS subscription URL:", message.SubscribeURL);
request(message.SubscribeURL, function (err, res, body) {
request(message.SubscribeURL, function (err, _res, _body) {
if (err){ console.log(err); }
});
// Else set the bob media status to true
Expand Down
12 changes: 11 additions & 1 deletion routes/browser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const express = require('express');
var router = express.Router();

adminPassword = process.env.ADMIN_PASSWORD;
const adminPassword = process.env.ADMIN_PASSWORD;
const ABE_API_URI = (process.env.ABE_API_URI || 'https://abe-api-dev.herokuapp.com/')
.replace(/\/$/, '');

module.exports = function (api, rootDir) {
router.route('/').get(function(req, res) {
Expand Down Expand Up @@ -44,6 +46,8 @@ module.exports = function (api, rootDir) {
if (req.params.bobid.length === 24){
db.Bob.getOneBob({ _id: db.ObjectId(req.params.bobid)}).then(function success(data) {
if (data){
// FIXME: this is probably an error. Fix it after adding a test.
// eslint-disable-next-line no-undef
res.sendFile(path.join(rootDir, '/templates/editbob.html'));
} else {
res.status(404).send("bob not found");
Expand All @@ -56,6 +60,12 @@ module.exports = function (api, rootDir) {
}
});

router.route('/config.js')
.get(function(req, res) {
res.type('application/javascript')
.send("const ABE_API_URI = " + JSON.stringify(ABE_API_URI) + ";");
});

return router;
};

Expand Down
4 changes: 2 additions & 2 deletions routes/sockets.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = function(io, db) {
module.exports = function(io, _db) {

io.on('connection', function(socket) {
io.on('connection', function(_socket) {
console.log("socket connected");
});
};
4 changes: 1 addition & 3 deletions routes/twilio.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// External dependencies
const path = require('path');
const re = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g

module.exports = function(io, db) {

var twilio = {};

twilio.POSTtext = function(req, res, next) {
twilio.POSTtext = function(req, res, _next) {
var startDate = new Date();
var endDate = new Date().setDate(startDate.getDate() + 7);

Expand Down
2 changes: 1 addition & 1 deletion scripts/importDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const collectionName = process.argv[2];
db.on('open', function () {

fs.readFile(collectionName + '.json', 'utf8', (err, data) => {
objects = JSON.parse(data);
const objects = JSON.parse(data);
console.log('importing', objects.length, collectionName, 'from', collectionName + '.json');


Expand Down
2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if(process.env.NODE_ENV === 'production'){
app.use(enforce.HTTPS({ trustProtoHeader: true }));
}

port = process.env.PORT || 8080;
const port = process.env.PORT || 8080;
http.listen(port, function() {
console.log("FORWARDboard running over http on port", port);
});
Expand Down
2 changes: 1 addition & 1 deletion static/js/board_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function scrollEvents($collectionSelection, scrollToBottom = true) {
$(function(){

// parse events from abe JSON URL
$.get('https://abe.olin.build/events/', populateEvents);
$.get(ABE_API_URI + '/events/', populateEvents);

// Initializes auto scroll for events
var $eventsToday = $('.today .autoscrolling > .collection')
Expand Down
1 change: 1 addition & 0 deletions templates/board.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<link rel="stylesheet" type="text/css" href="/static/css/board_mobile.css">

<!-- load board components-->
<script src='/config.js' charset="UTF-8" type="text/javascript"></script>
<script src='/static/js/board_carousel.js' charset="UTF-8" type="text/javascript"></script>
<script src='/static/js/board_events.js' charset="UTF-8" type="text/javascript"></script>

Expand Down
1 change: 1 addition & 0 deletions templates/events.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<link rel="stylesheet" type="text/css" href="/static/css/events-only.css">

<!-- load board components-->
<script src='/config.js' charset="UTF-8" type="text/javascript"></script>
<script src='/static/js/board_events.js' charset="UTF-8" type="text/javascript"></script>

<!-- load board js -->
Expand Down
Loading

0 comments on commit 7382aa4

Please sign in to comment.