-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
53 lines (44 loc) · 1.46 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
import express, { static as static_ } from "express";
import { ApolloServer } from "@apollo/server";
import { expressMiddleware } from "@apollo/server/express4";
import http from "http";
import bodyParser from "body-parser";
import cors from "cors";
import { ApolloServerPluginDrainHttpServer } from "@apollo/server/plugin/drainHttpServer";
//* ---------------- files import --------------
import { connectMongo } from "./db/db.js";
import { typeDefs } from "./graphql/types/typeDefs.js";
import { resolvers } from "./graphql/resolvers/index.js";
import userFileUpload from "./router/userFileUpload.js";
// ----------------------------------
await connectMongo();
const app = express();
const port = 4000;
const httpServer = http.createServer(app);
const server = new ApolloServer({
typeDefs,
resolvers,
plugins: [ApolloServerPluginDrainHttpServer({ httpServer })],
});
await server.start();
app.use("/images/vehicle", static_("public/images/vehicle"));
app.use(
"/images/user-profile-images",
static_("public/images/user-profile-images")
);
app.use(
cors()
);
app.use(bodyParser.json());
app.use(userFileUpload);
app.use(
"/graphql",
expressMiddleware(server, {
context: async ({ req }) => ({ req }),
})
);
// httpServer.listen(port,() => {
// console.log(`🚀 Server ready at http://localhost:${port}`);
// },);
await new Promise((resolve) => httpServer.listen({ port: port }, resolve));
console.log(`🚀 Server ready at http://localhost:4000/graphql`);