-
Notifications
You must be signed in to change notification settings - Fork 3
/
devServer.js
101 lines (70 loc) · 2.76 KB
/
devServer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
var path = require('path');
var express = require('express');
var session = require('express-session');
var cookieParser = require('cookie-parser');
//Extras
var bodyParser = require('body-parser');
var db = require('./server/config/dbOperations.js');
var User = require('./server/controllers/userController.js');
var passport = require('passport');
//Webpack
var webpack = require('webpack');
var config = require('./webpack.config.dev');
var compiler = webpack(config);
var app = express();
//Body Parser
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(cookieParser());
app.use(session({
secret: 'FOOD1234567890BOT',
resave: false,
saveUninitialized: false
}));
// use passport
app.use( passport.initialize());
// store passport authentication in the session
app.use( passport.session());
//Hot Reloading
app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: config.output.publicPath
}));
app.use(require('webpack-hot-middleware')(compiler));
app.use(express.static(__dirname + '/dist'));
require('./server/config/routes.js')(app, express);
var port = process.env.PORT || 3000;
app.get('*', function(req, res) {
res.sendFile(path.join(__dirname, 'index.html'));
});
app.listen(3000, function(err) {
if (err) {
console.log(err);
return;
}
console.log('Listening at http://localhost:3000');
});
//postgres set up
var pg = require('pg');
var connectionString = process.env.DATABASE_URL || 'postgresql://localhost/foodbot';
var client = new pg.Client(connectionString);
client.connect();
//create db tables
var createUsersTable = client.query(db.createUsersTable);
var createRecipeSourcesTable = client.query(db.createRecipeSourcesTable);
var createRecipesTable = client.query(db.createRecipesTable);
var createGroceriesTable = client.query(db.createGroceryPriceTable);
var createIngredientsTable = client.query(db.createIngredientsTable);
var createRecipeIngredientsTable = client.query(db.createRecipeIngredientsTable);
var createProfilesTable = client.query(db.createProfilesTable);
var createUserRecipesTable = client.query(db.createUserRecipesTable);
var createMatchesQueueTable = client.query(db.createMatchesQueueTable);
var createUserPhotosTable = client.query(db.createUserPhotosTable);
var createOrdersTable = client.query(db.createOrdersTable);
var createRecipeCostTable = client.query(db.createRecipeCostTable);
var createRecipeSourcesTable = client.query(db.createRecipeSourcesTable);
var seedRecipeSourcesTable = client.query("SELECT * from RecipeSources", db.checkForSourceIds);
var createRecipeSearchTerms = client.query(db.createRecipeSearchTerms);
var seedRecipeSearchTerms = client.query('Select * from RecipeSearchTerms', db.checkForSeededResults);
// client.end();
module.exports = app;