-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (51 loc) · 1.72 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
const path = require("node:path");
const express = require("express");
const morgan = require("morgan");
const mongoose = require("mongoose");
const multer = require("multer");
const { graphqlHTTP } = require("express-graphql");
const feedRoutes = require("./routes/feed");
const authRoutes = require("./routes/auth");
const adminRoutes = require("./routes/admin");
const errorController = require("./controllers/error");
const setHeaders = require("./middlewares/setHeaders");
const auth = require("./middlewares/auth");
const imageControllers = require("./graphql/image.controllers");
const { fileStorage, fileFilter } = require("./service/image.service");
const graphqlSchema = require("./graphql/schema");
const graphqlResolver = require("./graphql/resolvers");
const app = express();
const PORT = 3000;
app.use(morgan("dev"));
require("dotenv").config();
app.use(express.json()); // parse incoming json data
app.use(multer({ storage: fileStorage, fileFilter }).single("image"));
app.use("/images", express.static(path.join(__dirname, "images")));
app.use(auth);
app.use(setHeaders);
// handle saving image put request
app.put("/attach-image-url", imageControllers);
app.use(
"/graphql",
graphqlHTTP({
schema: graphqlSchema,
rootValue: graphqlResolver,
graphiql: true,
})
);
app.use("/auth", authRoutes);
app.use("/feed", feedRoutes);
app.use("/admin", adminRoutes);
app.use(errorController);
mongoose
.connect(process.env.MONGO_URI)
.then((result) => {
const server = app.listen(PORT, () => {
console.log("Connected TO http://localhost:" + PORT);
});
const io = require("./socket").init(server);
io.on("connection", (socket) => {
console.log("Client connected!");
});
})
.catch(console.error);