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

75 lines
2.1 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';
2016-06-14 01:29:33 +02:00
const MongoStore = require('connect-mongo')(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';
import users from './routes/user.routes';
2016-06-14 22:48:16 +02:00
import sessions from './routes/session.routes';
2016-05-03 06:09:16 +02:00
//Body parser, cookie parser, sessions, serve public assets
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());
2016-06-14 01:29:33 +02:00
app.use(session({
resave: true,
saveUninitialized: false,
secret: process.env.SESSION_SECRET,
proxy: true,
name: 'sessionId',
cookie: {
httpOnly: true,
secure: false,
},
store: new MongoStore({
url: process.env.MONGO_URL,
autoReconnect: true
})
}));
app.use(passport.initialize());
app.use(passport.session());
app.use('/', users);
2016-06-14 22:48:16 +02:00
app.use('/', sessions);
2016-05-03 06:09:16 +02:00
const passportConfig = require('./config/passport');
2016-06-09 19:56:23 +02:00
//Connect to MongoDB
// mongoose.connect(process.env.MONGODB_URI || process.env.MONGOLAB_URI);
mongoose.connect(serverConfig.mongoURL);
mongoose.connection.on('error', () => {
console.error('MongoDB Connection Error. Please make sure that MongoDB is running.');
process.exit(1);
});
2016-05-03 06:09:16 +02:00
app.get("/", function(req, res) {
res.sendFile(path.resolve(__dirname + '/../index.html'));
})
// 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;