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

[MAD PP] Ismael & Nico #2

Open
wants to merge 1 commit 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
4 changes: 3 additions & 1 deletion server/.env
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
MONGODB_URI=mongodb://localhost/irontrello
PORT=3000
ENV=development
DBURL=mongodb://localhost/trello
8 changes: 7 additions & 1 deletion server/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# Dependency directory
node_modules
.DS_Store

# Debug log from npm
npm-debug.log

# Environment Variables should NEVER be published
.env
13 changes: 13 additions & 0 deletions server/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "DEBUG Irongenerate",
"port": 9229,
"protocol": "inspector",
"restart": "true"
}
]
}
61 changes: 0 additions & 61 deletions server/api/card/card.controller.js

This file was deleted.

26 changes: 0 additions & 26 deletions server/api/card/card.model.js

This file was deleted.

23 changes: 0 additions & 23 deletions server/api/list/list.model.js

This file was deleted.

79 changes: 52 additions & 27 deletions server/app.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,70 @@
require("dotenv").config();
const express = require('express');
const path = require('path');
const favicon = require('serve-favicon');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const cors = require('cors');
const mongoose = require('mongoose');

const app = express();

app.use(cors());

app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");
const express = require("express");
const favicon = require("serve-favicon");
const hbs = require("hbs");
const mongoose = require("mongoose");
const logger = require("morgan");
const path = require("path");
const cors = require("cors")

mongoose.Promise = Promise;
mongoose
.connect(process.env.MONGODB_URI, { useMongoClient: true })
.connect(
process.env.DBURL,
{ useMongoClient: true }
)
.then(() => {
console.log("Connected to Mongo!");
})
.catch(err => {
console.error("Error connecting to mongo", err);
});

app.set('view engine', 'jade');
const app_name = require("./package.json").name;
const debug = require("debug")(
`${app_name}:${path.basename(__filename).split(".")[0]}`
);

const app = express();

require('./routes')(app);
var whitelist = [
'http://localhost:4200',
];
var corsOptions = {
origin: function(origin, callback){
var originIsWhitelisted = whitelist.indexOf(origin) !== -1;
callback(null, originIsWhitelisted);
},
credentials: true
};
app.use(cors(corsOptions));
// Middleware Setup
app.use(logger("dev"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());

// Express View engine setup

app.use(
require("node-sass-middleware")({
src: path.join(__dirname, "public"),
dest: path.join(__dirname, "public"),
sourceMap: true
})
);

app.set("views", path.join(__dirname, "views"));
app.set("view engine", "hbs");
app.use(express.static(path.join(__dirname, "public")));
app.use(favicon(path.join(__dirname, "public", "images", "favicon.ico")));

app.use(function(err, req, res, next) {
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// default value for title local
app.locals.title = "Express - Generated with IronGenerator";

res.status(err.status || 500);
res.render('error');
});
const index = require("./routes/index")(app);

module.exports = app;
94 changes: 24 additions & 70 deletions server/bin/www
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,90 +1,44 @@
#!/usr/bin/env node
const http = require('http');

/**
* Module dependencies.
*/
let app = require('../app');

var app = require('../app');
var debug = require('debug')('trello:server');
var http = require('http');
// catch 404 and render a not-found.hbs template
app.use((req, res, next) => {
res.status(404);
res.render('not-found');
});

/**
* Get port from environment and store in Express.
*/
app.use((err, req, res, next) => {
// always log the error
console.error('ERROR', req.method, req.path, err);

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

/**
* Create HTTP server.
*/

var server = http.createServer(app);

/**
* 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;
// only render if the error ocurred before sending the response
if (!res.headersSent) {
res.status(500);
res.render('error');
}
});

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

return false;
}

/**
* Event listener for HTTP server "error" event.
*/
let server = http.createServer(app);

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

var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
server.on('error', error => {
if (error.syscall !== 'listen') { throw error }

// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
console.error(`Port ${process.env.PORT} requires elevated privileges`);
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
console.error(`Port ${process.env.PORT}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);
}
server.listen(process.env.PORT, () => {
console.log(`Listening on http://localhost:${process.env.PORT}`);
});
Loading