clean up development config

This commit is contained in:
Eric Hulburd
2016-02-09 11:16:49 -06:00
parent 109ad432bb
commit a334afbc01
20 changed files with 170 additions and 111 deletions

View File

@@ -6,46 +6,71 @@ import express from 'express';
import path from 'path';
import webpack from 'webpack';
import WebpackDevServer from 'webpack-dev-server';
import schema from './config/graphql/schema';
import bodyParser from 'body-parser';
import DB from './config/database';
import routes from './routes';
const API_PORT = 8080;
const APP_PORT = 3000;
const JS_PORT = 3000;
var app = express();
var api = express();
/*
* Serve API App
*/
DB.sync().then(()=>{
routes(app);
routes(api);
api.use(bodyParser.json());
api.use(bodyParser.urlencoded({ extended: false }));
api.listen(API_PORT, () => {
console.log(`API is now running on http://localhost:${API_PORT}`);
});
});
/*
* Logging, Cookie, JSON Parsing Middleware
* Development Server
*/
import favicon from 'serve-favicon';
import logger from 'morgan';
import cookieParser from 'cookie-parser';
import bodyParser from 'bodyParser';
// uncomment after placing your favicon in /public
app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
var config = require('./config/webpack/development'),
dev_server = new WebpackDevServer(webpack(config), {
contentBase: __dirname + '/../client/build/development',
publicPath: "/assets/",
proxy: {
'/data': `http://localhost:${APP_PORT}`,
},
stats: {colors: true}
}),
app = dev_server.app;
/*
* Serve Vendor Scripts, CSS, and Templates
*/
import favicon from 'serve-favicon';
import logger from 'morgan';
// uncomment after placing your favicon in /public
app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
// serve fonts in /assets/fonts
import assets from "connect-assets";
app.use("/assets/fonts", express.static("node_modules/bootstrap/dist/fonts"));
app.use("/assets/fonts", express.static("node_modules/font-awesome/fonts"));
// TODO: These routes need to match references in the bootstrap and font awesome files.
app.use("/assets/fonts", express.static("bootstrap/dist/fonts"));
app.use("/assets/fonts", express.static("font-awesome/fonts"));
// serve compiled vendor assets and application.css.
app.use(assets({
paths: ["./assets/js", "./assets/css", "./../node_modules"],
paths: ["./../node_modules"],
build: true,
buildDir: false,
//compile: false,
@@ -61,9 +86,6 @@ app.get("/", (req, res, next)=>{
res.render("index");
});
app.listen(APP_PORT, () => {
console.log(`App is now running on http://localhost:${APP_PORT}`);
});
/*
* Handle Errors
@@ -98,55 +120,8 @@ app.use(function(err, req, res, next) {
});
});
dev_server.listen(APP_PORT, () => {
console.log(`App is now running on http://localhost:${APP_PORT}`);
});
/*
* Development Server
*/
import ExtractTextPlugin from "extract-text-webpack-plugin";
var compiler = webpack({
entry: {
app: __dirname + '/../client/app.js',
style: __dirname + '/../client/style.scss'
},
output: {
filename: '[name].js',
path: __dirname + '/../client/build'
},
externals: {
jquery: "$",
d3: "d3"
},
module: {
loaders: [
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract("style-loader", "css-loader!sass-loader")
}, {
test: /\.css$/,
loader: ExtractTextPlugin.extract("style-loader", "css-loader")
}
]
},
// Use the plugin to specify the resulting filename (and add needed behavior to the compiler)
plugins: [
new ExtractTextPlugin("style.css", {
allChunks: true
})
]
});
var dev_server = new WebpackDevServer(compiler, {
contentBase: __dirname + '/../client/build',
publicPath: "/assets/",
proxy: {
'/data': `http://localhost:${APP_PORT}`
},
stats: {colors: true}
});
module.exports = app;

View File

@@ -0,0 +1,17 @@
import fs from 'fs';
const CONTROLLER_DIR = __dirname + '/../controllers';
class Controllers {
static sync(){
fs.readdirSync(CONTROLLER_DIR).forEach(function(file) {
var controller = require(CONTROLLER_DIR + '/' + file);
Controllers[controller.NAME] = controller;
});
return true;
}
}
export default Controllers;

View File

@@ -10,15 +10,15 @@ var sequelize = new Sequelize("postgres://spikeuser:123456@localhost:5432/spike2
idle: 10000
}
});
const model_dir = __dirname + '/../models'
const MODEL_DIR = __dirname + '/../models'
class Database {
static sync(){
console.log("syncing db")
fs.readdirSync(model_dir).forEach(function(file) {
var model = require(model_dir + '/' + file);
Database[model.name] = model;
fs.readdirSync(MODEL_DIR).forEach(function(file) {
var model = require(MODEL_DIR + '/' + file);
Database[model.NAME] = model;
Database.models.push(model);
});

View File

@@ -1,5 +1,7 @@
export default {
var config = {
modules: 'es6',
'target-version': '0.14.3',
'suffix': '.rt'
targetVersion: '0.14.0',
suffix: '.rt'
};
export default config;

View File

@@ -1,3 +1,5 @@
import webpack from 'webpack';
const ROOT = __dirname + '/../../../';
module.exports = {
@@ -17,21 +19,20 @@ module.exports = {
loaders: [
{
test: /\.scss$/,
loader: ['style', 'raw', 'sass']
loaders: ['style', 'raw', 'sass']
}, {
test: /\.css$/,
loader: ['style', 'raw']
loaders: ['style', 'raw']
}, {
test: /\.js$/,
loader: 'babel'
}
]
},
sassLoader: {
includePaths: [ROOT + 'client', ROOT + 'node_modules']
},
// Use the plugin to specify the resulting filename (and add needed behavior to the compiler)
plugins: [
new ExtractTextPlugin("style.css", {
allChunks: true
}),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",

View File

@@ -1,13 +1,18 @@
import DB from './../config/database.js';
const NAME = 'EnergyController';
class EnergyController{
static index(req, res){
DB.House.findOne({where: {name: req.housename}}).then((house)=>{
house.getEnergyDataByTime(req.params.start_time, req.params.end_time).then((energy_data){
house.getEnergyDataByTime(req.params.start_time, req.params.end_time).then((energy_data)=>{
req.json(energy_data);
});
});
}
}
EnergyController.NAME = NAME;
module.exports = EnergyController;

View File

@@ -1,11 +1,16 @@
import DB from './../config/database.js';
const NAME = HousesController;
class HousesController{
static index(req, res){
DB.House.findAll({attributes: ['id', 'name']}).then((houses){
DB.House.findAll({attributes: ['id', 'name']}).then((houses)=>{
res.json(houses);
});
}
}
HousesController.NAME = NAME;
module.exports = HousesController;

View File

@@ -1,13 +1,18 @@
import DB from './../config/database.js';
const NAME = 'PowerController';
class PowerController{
static index(req, res){
DB.House.findOne({where: {name: req.housename}}).then((house)=>{
house.getPowerDataByTime(req.params.start_time, req.params.end_time).then((power_data){
house.getPowerDataByTime(req.params.start_time, req.params.end_time).then((power_data)=>{
res.json(power_data);
});
});
}
}
PowerController.NAME = NAME;
module.exports = PowerController;

View File

@@ -34,8 +34,7 @@ export default function (opt) {
var options = extend({
filename: file.path,
sourceFiles: [file.relative],
generatedFile: replaceExtension(file.relative),
suffix: '.rt'
generatedFile: replaceExtension(file.relative)
}, opt);
if (options.suffix && !options.name) {

View File

@@ -32,5 +32,5 @@ var EnergyDatum = DB.sequelize.define(NAME, {
}
});
EnergyDatum.name = NAME;
EnergyDatum.NAME = NAME;
module.exports = EnergyDatum;

View File

@@ -1,6 +1,5 @@
import moment from 'moment-timezone';
import DB from "./../config/database";
import {nodeInterface} from './../config/graphql/node';
const NAME = 'House';
@@ -76,5 +75,5 @@ var House = DB.sequelize.define(NAME, {
}
});
House.name = NAME;
House.NAME = NAME;
module.exports = House;

View File

@@ -1,6 +1,6 @@
import DB from "./../config/database";
const NAME = 'PowerDatum'
const NAME = 'PowerDatum';
/**
* Define your own types here
@@ -32,5 +32,5 @@ var PowerDatum = DB.sequelize.define(NAME, {
}
});
PowerDatum.name = NAME;
PowerDatum.NAME = NAME;
module.exports = PowerDatum;

View File

@@ -1,9 +1,11 @@
import Controllers from 'controllers'
import Controllers from './config/controllers'
export default function(app){
app.use('/data/v1/savings/:housename', Controllers.Energy.savings);
app.use('/data/v1/production/:housename', Controllers.Energy.production);
app.use('/data/v1/houses/:housename');
Controllers.sync();
app.use('/data/v1/savings/:housename', Controllers.PowerController.index);
app.use('/data/v1/production/:housename', Controllers.EnergyController.index);
app.use('/data/v1/houses/', Controllers.EnergyController.index);
};

View File

@@ -4,8 +4,6 @@ html
meta(charset='utf-8')
meta(http-equiv='content-type', content='text/html; charset=UTF-8')
meta(name='viewport', content='width=device-width, initial-scale=1')
!= css("vendor")
!= css("application")
title Spike Prototype
body
#spike_container
@@ -23,7 +21,7 @@ html
ul.nav.navbar-nav.navbar-right
li
a(href='/') Spike
block content
block content
#spike_footer
.container Footer
script(type='text/javascript').
@@ -31,5 +29,5 @@ html
// in developer tools for the native `fetch`.
self.fetch = null;
script(src='http://localhost:3000/webpack-dev-server.js')
!= js("vendor")
script(src='/assets/js/application.js')
script(src='/assets/style.js')
script(src='/assets/app.js')