-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevelopment.ts
55 lines (46 loc) · 1.37 KB
/
development.ts
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
import { ApolloServer } from "apollo-server-express";
import express from "express";
import { typeDefs, resolvers } from "./apolloserver.js";
export const server = new ApolloServer({
typeDefs,
resolvers,
context: ({ req, res }) => ({
gitbookApiToken: req.headers.authorization.split(" ")[1],
}),
});
const app = express();
app.get("/", (req, res) => {
res.send(`<html>
<head>
<title>Simple GraphiQL Example</title>
<link href="https://unpkg.com/graphiql/graphiql.min.css" rel="stylesheet" />
</head>
<body style="margin: 0;">
<div id="graphiql" style="height: 100vh;"></div>
<script
crossorigin
src="https://unpkg.com/react/umd/react.production.min.js"
></script>
<script
crossorigin
src="https://unpkg.com/react-dom/umd/react-dom.production.min.js"
></script>
<script
crossorigin
src="https://unpkg.com/graphiql/graphiql.min.js"
></script>
<script>
const fetcher = GraphiQL.createFetcher({ url: '/graphql' });
ReactDOM.render(
React.createElement(GraphiQL, { fetcher: fetcher, headerEditorEnabled: true, shouldPersistHeaders: true }),
document.getElementById('graphiql'),
);
</script>
</body>
</html>`);
});
await server.start();
server.applyMiddleware({ app });
app.listen({ port: process.env.PORT || 4000 }, () => {
console.log("Server ready!");
});