-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
84 lines (67 loc) · 1.9 KB
/
app.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
const dotenv = require("dotenv");
dotenv.config({ path: "./config.env" });
const cookieParser = require("cookie-parser");
const express = require("express");
const mongoose = require("mongoose");
const app = express();
const { cloudinary } = require("./utils/cloudinary");
require("./db/conn");
app.use(express.json({ limit: "50mb" }));
app.use(express.urlencoded({ limit: "50mb", extended: true }));
app.use(express.json());
app.use(cookieParser());
app.use((req, res, next) => {
// Website you wish to allow to connect
res.setHeader(
"Access-Control-Allow-Origin",
"https://events-galore-frontend.vercel.app"
);
// Request methods you wish to allow
res.setHeader(
"Access-Control-Allow-Methods",
"GET, POST, OPTIONS, PUT, PATCH, DELETE"
);
// Request headers you wish to allow
res.setHeader(
"Access-Control-Allow-Headers",
"X-Requested-With,content-type"
);
// Set to true if you need the website to include cookies in the requests sent
// to the API (e.g. in case you use sessions)
res.setHeader("Access-Control-Allow-Credentials", true);
next();
});
app.use(require("./router/auth"));
// app.get("/", (req, res) => {
// res.send("HELLO THERE");
// });
// const middleware = (req, res, next) => {
// console.log("hello middle");
// next();
// };
const PORT = 2000;
app.get("/createv", (req, res) => {
res.send("CREATE EVENT");
});
app.get("/event", (req, res) => {
res.send("EVENTS:");
});
app.listen(PORT, () => {
console.log("server is running on " + PORT);
});
app.use(express.static("public"));
let imageurl = "";
app.post("/image", async (req, res) => {
try {
const fileStr = req.body.data;
const uploadResponse = await cloudinary.uploader.upload(fileStr, {
upload_preset: "eventimages",
});
imageurl = uploadResponse.url;
res.send(imageurl);
console.log(imageurl);
} catch (err) {
console.error(err);
}
});
app.get("/image", (req, res) => res.send({ imageurl }));