2016-02-22 14:36:07 -06:00
|
|
|
/*
|
|
|
|
|
* Serve GraphQL Backend
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import express from 'express';
|
|
|
|
|
import path from 'path';
|
|
|
|
|
import webpack from 'webpack';
|
|
|
|
|
import WebpackDevServer from 'webpack-dev-server';
|
|
|
|
|
import bodyParser from 'body-parser';
|
|
|
|
|
|
|
|
|
|
import DB from './config/database';
|
|
|
|
|
import routes from './routes';
|
|
|
|
|
|
|
|
|
|
const API_PORT = 8080;
|
|
|
|
|
const APP_PORT = 3000;
|
|
|
|
|
|
2016-02-22 20:02:45 -06:00
|
|
|
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
|
|
|
|
|
2016-02-22 14:36:07 -06:00
|
|
|
var api = express();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Serve API App
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
DB.sync().then(()=>{
|
|
|
|
|
|
|
|
|
|
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}`);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Development Server
|
|
|
|
|
*/
|
|
|
|
|
|
2016-02-23 12:34:27 -06:00
|
|
|
var config = require('./../client/config/development/webpack'),
|
2016-02-22 14:36:07 -06:00
|
|
|
dev_server = new WebpackDevServer(webpack(config), {
|
2016-02-23 12:34:27 -06:00
|
|
|
contentBase: './../client/build/development',
|
2016-02-22 14:36:07 -06:00
|
|
|
publicPath: "/assets/",
|
|
|
|
|
proxy: {
|
|
|
|
|
'/data*': `http://localhost:${API_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";
|
|
|
|
|
|
|
|
|
|
// 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: ["./../node_modules"],
|
|
|
|
|
build: true,
|
|
|
|
|
buildDir: false,
|
2016-02-29 18:20:00 -06:00
|
|
|
// compile: false,
|
2016-02-22 14:36:07 -06:00
|
|
|
compress: true
|
|
|
|
|
}));
|
|
|
|
|
// serve public static files.
|
|
|
|
|
dev_server.app.use('/', express.static(path.resolve(__dirname, 'public')));
|
|
|
|
|
|
|
|
|
|
// view engine set up
|
|
|
|
|
app.set('views', path.join(__dirname, 'views'));
|
|
|
|
|
app.set('view engine', 'jade');
|
2016-02-29 18:20:00 -06:00
|
|
|
app.get("*", (req, res, next)=>{
|
2016-02-22 14:36:07 -06:00
|
|
|
res.render("index");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
dev_server.listen(APP_PORT, () => {
|
|
|
|
|
console.log(`App is now running on http://localhost:${APP_PORT}`);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
module.exports = app;
|