-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (35 loc) · 1.34 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
const cors = require("cors");
const express = require("express");
const mongoose = require("mongoose");
const {graphqlUploadExpress} = require('graphql-upload');
const { typeDefs } = require("./schema/type-defs");
const { resolvers } = require("./schema/resolvers");
const { ApolloServer } = require("apollo-server-express");
async function startServer() {
const app = express();
const app_port = 4600;
const mongo_port = 27017;
const server = new ApolloServer({ typeDefs, resolvers });
await server.start();
app.use(graphqlUploadExpress({ maxFileSize: 10000000, maxFiles: 100 }));
server.applyMiddleware({ app });
app.use(express.static("public"));
app.use(cors());
app.get("/", (req, res) => {
const element_style = `text-align:center;
color:green;
background-color:black;
border:1px solid green;
border-radius:.25em;
padding:5em;`;
res.send(`<div style='${element_style}'>
<h3>Server is running on <a href='http://localhost:${app_port}/graphql'>http://localhost:${app_port}/graphql</a></h3>
</div>`);
});
await mongoose.connect(`mongodb://localhost:${mongo_port}/Documentation-System`);
app.listen(app_port, () => {
console.log(`Server is running on http://localhost:${app_port}/graphql.`);
});
}
startServer();
// npm i express apollo-server-express mongoose graphql nodemon