Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coreys branch #1

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
6930a4c
Just adding dependencis to packages.json and some common package desc…
devspacenine Aug 23, 2016
c59a7db
Just some .gitignore additions that exclude transformed JS and CSS (a…
devspacenine Aug 23, 2016
e33741d
Added express setup code for serving static files and a base.html. (A…
devspacenine Aug 23, 2016
5583f02
Added gulpfile with task definitions for building SCSS, transforming …
devspacenine Aug 23, 2016
ffa5045
Added entrypoint for client-side JS code that sets up ReactJS with Re…
devspacenine Aug 23, 2016
18818c3
Added a module that configures the Redux store and all of its middleware
devspacenine Aug 23, 2016
bd29240
Added the route definitions of the SPA using react-router
devspacenine Aug 23, 2016
c5d41fa
Added container components that make up the different route configura…
devspacenine Aug 23, 2016
aba60f6
Added a nav bar component that is used in the App container
devspacenine Aug 23, 2016
ba97b52
Middleware that helps with debugging/replaying all of a user's actions
devspacenine Aug 23, 2016
5e269d1
Middleware that allows for actions that will store state data in the …
devspacenine Aug 23, 2016
952ff44
Middleware that allows for actions that will make an AJAX request to …
devspacenine Aug 23, 2016
2ef5c95
Actions are methods used by components to announce changes that affec…
devspacenine Aug 23, 2016
1795091
Reducers are methods that receive every action (as an object returned…
devspacenine Aug 23, 2016
378e931
Dockerized the node application and created a linked MySQL container.…
devspacenine Aug 23, 2016
a71bd1e
Just some utility methods for working with react and redux
devspacenine Aug 23, 2016
d2cbc66
Ignore: left bug in App container component
devspacenine Aug 23, 2016
8a58ed8
Ignore: leftover bugs in container components
devspacenine Aug 23, 2016
36e5c59
Fixed some linting issues
devspacenine Aug 23, 2016
2922938
Made API responses follow similar patterns and always return JSON (He…
devspacenine Aug 23, 2016
a93d69e
Moved API routes into their own express.Router
devspacenine Aug 23, 2016
a970f89
Clarifying comment
devspacenine Aug 23, 2016
6e9a4c8
Fixed small issue with API redux middleware
devspacenine Aug 23, 2016
67e34de
Ignore: Made players routes more robust and organized
devspacenine Aug 23, 2016
bbc7edb
Added redux action dispatchers and constants for the user and player …
devspacenine Aug 23, 2016
592cab0
Added redux action reducers that define how to update the redux state…
devspacenine Aug 23, 2016
07c33e1
Added routes for players and users views
devspacenine Aug 23, 2016
0908dc9
Tweaked routes a little bit
devspacenine Aug 23, 2016
ab6b558
Added a dashboard page that will be landed on at the root url
devspacenine Aug 23, 2016
d374e1c
Simple pass through component to facilitate deeper path levels in routes
devspacenine Aug 23, 2016
f408917
Added users list page and a user profile page
devspacenine Aug 23, 2016
f31e25c
Added players list page and a player profile page
devspacenine Aug 23, 2016
464f81d
Renaming some variables and directory names
devspacenine Aug 23, 2016
2a2862b
Added players and users options to the nav
devspacenine Aug 23, 2016
fd080cd
Ignore: Couple nav tweaks
devspacenine Aug 23, 2016
0fe6536
Added bootstrap icon fonts
devspacenine Aug 23, 2016
d8e1177
API was not returning JSON because of bad header check
devspacenine Aug 23, 2016
ffad52e
Making user actions similar to player actions
devspacenine Aug 23, 2016
7a87398
Made the tables more consistent
devspacenine Aug 23, 2016
06d7822
Created the player and user list components, along with event hooks f…
devspacenine Aug 23, 2016
58d6f23
Fixed some issues and fully implemented the users endpoints and actio…
devspacenine Aug 23, 2016
79e718f
Removed example code and cleaned up a little
devspacenine Aug 23, 2016
f1d120e
Added more AJAX request verbs to the players and users reducers
devspacenine Aug 23, 2016
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
56 changes: 36 additions & 20 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
const express = require('express');
const bodyParser = require('body-parser');
const data = require('./libs/data');
const players = require('./libs/data/players');
const app = express();
const port = 8080;
'use strict';

var express = require('express'),
bodyParser = require('body-parser'),
data = require('./libs/data'),
players = require('./libs/data/players'),
swig = require('swig'),
app = express(),
port = 8080;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its a good practice to chain your declarations as long as you can. Something about how v8 does optimization.

app.use((request, response, next) => {
//console.log(request.headers);
next()
next();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ending every line with a semicolon is also necessary for v8 optimization. Not that it matters for this project, but its a good practice.

});

// Body parsing middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true, limit: '50mb'}));

app.get('/', (request, response) => {
response.send('Hello from Express!');
});
// Swig Templating Setup
app.engine('html', swig.renderFile);
app.set('view engine', 'html');
app.set('views', __dirname + '/views');
app.set('view cache', false);
swig.setDefaults({cache: false});

// Setup static file server for images, html, css/fonts, and js
app.use('/public', express.static('public'));

app.get('/users', function(request, response) {

Expand All @@ -23,7 +34,7 @@ app.get('/users', function(request, response) {
response.send(users);
})
.catch(function(err) {
console.log(err)
console.log(err);
response.status(500).send(err);
});
});
Expand All @@ -34,11 +45,11 @@ app.post('/users', function(request, response) {
console.log(user);
data.createUser(user)
.then(function() {
console.log(arguments)
console.log(arguments);
response.send(`${user.username} created`);
})
.catch(function(err) {
console.log(err)
console.log(err);
response.status(500).send(err);
});
});
Expand Down Expand Up @@ -67,31 +78,36 @@ app.get('/players', function(request, response) {
app.get('/players/:id', function(request, response) {
players.findPlayer(request.params.id)
.then((player) => {
if (player == null) {
if (player === null) {
response.status(404).send();
}
else {
response.send(player);
}
})
.catch((err) => response.status(500).send(err))
.catch((err) => response.status(500).send(err));
});

app.delete('/players/:id', function(request, response) {
players.deletePlayer(request.params.id)
.then(() => response.status(204).send())
.catch((err) => response.status(500).send(err))
.catch((err) => response.status(500).send(err));
});

// Default route if no match was found for the url
app.all('/*', function (req, res) {
res.render('base', {});
});

app.use((err, request, response, next) => {
app.use((err, request, response) => {
console.log(err);
response.status(500).send('Something broke!')
response.status(500).send('Something broke!');
});

app.listen(port, (err) => {
if (err) {
return console.log('something bad happened', err)
return console.log('something bad happened', err);
}

console.log(`server is listening on ${port}`)
console.log(`server is listening on ${port}`);
});