forked from yangjiqi/Mini-Pinterest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
81 lines (69 loc) · 2.3 KB
/
server.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
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const path = require('path');
const http = require('http');
const cookieParser = require('cookie-parser');
const session = require('express-session');
const passport = require('passport');
app.use(cookieParser());
app.use(session({ secret: 'secret string xxxxxxx' }));
// app.use(session({ secret: process.env.SESSION_SECRET }));
app.use(passport.initialize());
app.use(passport.session());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, 'public')))
app.use(express.static(__dirname + '/dist'));
app.use(function(req, res, next) {
// res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Origin", "http://localhost:4200");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
res.header("Access-Control-Allow-Credentials", "true");
next();
});
require("./server/app")(app);
var recombee = require('recombee-api-client');
var rqs = recombee.requests;
var client = require("./server/model/model.server")
// client.send(new rqs.GetUserValues('alice'), function(error, res) {
// console.log(error);
// console.log(res);
// });
//
// client.send(new rqs.GetUserValues('alice'))
// .then(function (user) {
// console.log(user);
// })
// client.send(new rqs.ListItems({
// // 'returnProperties': true,
// 'filter': '\"photography\" in \'categories\'',
// }))
// .then(function (image) {
// console.log(image.length);
// })
// var result = []
// for (var itemId in ['image0', 'image1']) {
// var itemId =
// console.log(itemId);
// client.send(new rqs.GetItemValues(itemId))
// .then(function (image) {
// result.push(image);
// console.log(result);
// });
// }
// client.send(new rqs.AddPurchase('alice', 'image0'))
// .then(function (err, user) {
// console.log(err);
// console.log(user);
// })
//
// client.send(new rqs.RecommendItemsToUser('alice', 10), function(error, res) {
// console.log(error);
// console.log(res);
// });
const port = process.env.PORT || 3100;
app.set('port', port);
const server = http.createServer(app);
app.listen(port);