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

drewdiddy611's Solution' #23

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
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 .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015", "stage-0"]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# assignment_djello
Project management with that great wobbly taste.

Name: Andrew Senner
54 changes: 54 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const Koa = require("koa");
const staticServe = require("koa2-static").default;
const app = new Koa();
const onerror = require("koa-onerror");
const logger = require("koa-logger");
const koaSession = require("koa-session2");
require("babel-core/register");
require("babel-polyfill");

app.use(
staticServe({
root: __dirname + "/client/build",
path: "*"
})
);

// error handler
onerror(app);

app.use(logger());

// logger
app.use(async (ctx, next) => {
const start = new Date();
await next();
const ms = new Date() - start;
console.log(`${ctx.method} ${ctx.url} - ${ms}ms`);
});

const CONFIG = {
key: "koa:sess" /** (string) cookie key (default is koa:sess) */,
maxAge: 86400000 /** (number) maxAge in ms (default is 1 days) */,
overwrite: true /** (boolean) can overwrite or not (default true) */,
httpOnly: true /** (boolean) httpOnly or not (default true) */,
signed: true /** (boolean) signed or not (default true) */
};

const APP_SECRET = process.env.SECRET || "I Like Pickles";
app.keys = [APP_SECRET];

const session = koaSession(CONFIG, app);
app.use(session);

app.use(async (ctx, next) => {
// let n = ctx.session.views || 0;
// debug("app session: %s", n);
// ctx.session.views = ++n;
// await next();
});

module.exports = {
app,
session
};
97 changes: 97 additions & 0 deletions bin/www
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/usr/bin/env node

/**
* Module dependencies.
*/

var { app, session } = require('../app');
var debug = require('debug')('demo:server');
var http = require('http');

/**
* Get port from environment and store in Express.
*/

var port = normalizePort(process.env.PORT || '3001');
// app.set('port', port);

/**
* Create HTTP server.
*/

const socketService = require('../services/socketService');
var koaSocketSession = require('koa-socket-session');

var server = http.createServer(app.callback());
const IO = require('koa-socket.io');
const io = new IO({
namespace: '/'
});

io.start(server);
io.use(koaSocketSession(app, session));
io.on('connect', socketService);

/**
* Listen on provided port, on all network interfaces.
*/

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

/**
* Normalize a port into a number, string, or false.
*/

function normalizePort(val) {
var port = parseInt(val, 10);

if (isNaN(port)) {
// named pipe
return val;
}

if (port >= 0) {
// port number
return port;
}

return false;
}

/**
* Event listener for HTTP server "error" event.
*/

function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}

var bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port;

// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}

/**
* Event listener for HTTP server "listening" event.
*/

function onListening() {
var addr = server.address();
var bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port;
debug('Listening on ' + bind);
}
18 changes: 18 additions & 0 deletions client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
Loading