forked from vuejsdevelopers/vuejs-poster-shop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (52 loc) · 1.6 KB
/
index.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
var express = require("express");
var app = express();
var path = require("path");
var server = require("http").createServer(app);
var axios = require("axios");
var querystring = require("querystring");
var Pusher = require("pusher");
require("dotenv").config();
var pusher = new Pusher({
appId: process.env.PUSHER_APP_ID,
key: process.env.PUSHER_KEY,
secret: process.env.PUSHER_SECRET,
cluster: process.env.PUSHER_CLUSTER
});
var bodyParser = require("body-parser");
app.use(bodyParser.json());
app.get("/", function(req, res) {
res.sendFile(path.join(__dirname + "/index.html"));
});
var instance = axios.create({
baseURL: "https://api.imgur.com/3/",
headers: { Authorization: "Client-ID " + process.env.IMGUR_CLIENT_ID }
});
app.get("/search/:query", function(req, res) {
const url =
"gallery/search/top/0/?" + querystring.stringify({ q: req.params.query });
instance
.get(url)
.then(function(result) {
res.send(
result.data.data.filter(
item => !item.is_album && !item.nsfw && !item.animated
)
);
})
.catch(function(error) {
console.log(error);
});
});
app.post("/cart_update", (req, res) => {
//console.log("body", req.body);
pusher.trigger("cart", "update", req.body)
res.sendStatus(200);
});
app.use("/node_modules", express.static(path.join(__dirname, "node_modules")));
app.use("/public", express.static(path.join(__dirname, "public")));
if (process.env.NODE_ENV !== "production") {
require("reload")(server, app);
}
server.listen(process.env.PORT, function() {
console.log("Listening on port ".concat(process.env.PORT));
});