p5.js-web-editor/server/server.js

63 lines
1.8 KiB
JavaScript
Raw Normal View History

2016-05-03 06:09:16 +02:00
import Express from 'express';
import mongoose from 'mongoose';
import bodyParser from 'body-parser';
import cookieParser from 'cookie-parser';
import session from 'express-session';
import passport from 'passport';
2016-05-03 06:09:16 +02:00
import path from 'path';
//Webpack Requirements
import webpack from 'webpack';
import config from '../webpack.config';
import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
const app = new Express();
//add check if production environment here
const compiler = webpack(config);
app.use(webpackDevMiddleware(compiler, { noInfo: true, publicPath: config.output.publicPath }));
app.use(webpackHotMiddleware(compiler));
//Import all required modules
import serverConfig from './config';
//Body parser, cookie parser, sessions, serve public assets
const MongoStore = require('connect-mongo')(session);
2016-05-13 22:49:56 +02:00
app.use(Express.static(path.resolve(__dirname, '../static')));
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(cookieParser());
app.use(session({
//this should be SECRET AND IN A SECRET FILE
//TODO add dotenv
secret: 'steve brule',
resave: true,
saveUninitialized: true,
store: new MongoStore({
// url: process.env.MONGODB_URI || process.env.MONGOLAB_URI,
url: serverConfig.mongoURL,
autoReconnect: true
})
}));
app.use(passport.initialize());
app.use(passport.session());
2016-05-03 06:09:16 +02:00
const passportConfig = require('./config/passport');
2016-05-03 06:09:16 +02:00
app.get("/", function(req, res) {
res.sendFile(path.resolve(__dirname + '/../index.html'));
})
2016-05-24 07:20:59 +02:00
app.get("/login", function(req, res) {
res.sendFile(path.resolve(__dirname + '/../index.html'));
})
2016-05-03 06:09:16 +02:00
// start app
app.listen(serverConfig.port, (error) => {
if (!error) {
console.log(`p5js web editor is running on port: ${serverConfig.port}!`); // eslint-disable-line
}
});
export default app;