-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (32 loc) · 1.09 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
import express from 'express';
import typeDefs from './src/schema/index.js';
import path, { dirname } from 'path';
import { fileURLToPath } from 'url';
import { resolvers } from './src/resolvers/index.js';
import cors from 'cors';
import { ApolloServer } from 'apollo-server-express';
import { Vacancies } from './src/api/Vacancies.js';
const PORT = process.env.PORT || 5000;
const startServer = async () => {
const server = new ApolloServer({
typeDefs: typeDefs,
resolvers,
dataSources: () => {
return {
api: new Vacancies(),
};
},
});
await server.start();
const app = express();
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const buildPath = __dirname + '/client/build';
app.use(express.static(buildPath));
app.use('*', express.static(buildPath));
server.applyMiddleware({ app });
await new Promise(resolve => app.listen({ port: PORT }, resolve));
console.log(`🚀 Server ready at http://localhost:${PORT}${server.graphqlPath}`);
return { server, app };
};
const { app, server } = startServer();