-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (29 loc) · 902 Bytes
/
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
'use strict';
const { homedir } = require('os');
const { join } = require('path');
const http = require('http');
const { loadDB } = require('./lib/db');
const { createApp } = require('./lib/graphql/app');
function startServer ({port, app}) {
return new Promise((resolve, reject) => {
const actualPort = port || 8080;
const server = http.createServer(app);
server.listen(actualPort);
server.once('listening', () => resolve(server));
server.once('error', err => reject(err));
});
}
async function main() {
const dbDdir = join(homedir(), '.StarWarsDB');
const db = await loadDB(dbDdir);
//await db.reset();
const app = await createApp({
url: '/api/starWars',
db,
graphiql: true
});
const server = await startServer({port: 8080, app: app});
console.log(`GraphQL listening at ${server.address().port}`);
}
main()
.catch(err => console.error(err));