-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
45 lines (35 loc) · 1.24 KB
/
server.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
var express = require('express');
var graphqlHTTP = require('express-graphql');
var passport = require('passport');
var Strategy = require('passport-http').BasicStrategy;
var port = process.env.PORT || 8080;
var app = express();
// Auth
// =============================================================================
// Configure the Basic strategy for use by Passport. This has been disabled for now, but may be revisited in the future.
// Sets simple list of authorized users
var users = {
'govcon2018': 'govcon2018'
};
passport.use(new Strategy(
function (username, password, done) {
if (!users[username] || users[username] != password) {
return done(null, false);
}
return done(null, { username: username });
}
));
app.use(passport.authenticate('basic', { session: false }));
// Be able to use static files.
app.use(express.static('public'));
// Graphql
var schema = require('./graphql/_core/schema/_schema');
var resolvers = require('./graphql/_core/schema/_resolvers');
app.use('/graphql', graphqlHTTP({
schema: schema,
rootValue: resolvers,
graphiql: true,
}));
app.listen(port);
console.log('Starship example Middleware Server running on port ' + port);
console.log('Running a GraphQL API testing server at /graphql');