@@ -3,7 +3,8 @@ import * as os from "os";
3
3
const express = require ( "express" ) ;
4
4
import * as http from "http" ;
5
5
import * as proxy from "express-http-proxy" ;
6
-
6
+ const passport = require ( "passport" ) ;
7
+ const DigestStrategy = require ( "passport-http" ) . DigestStrategy ;
7
8
8
9
const debug = require ( "debug" ) ( "pipeline-api:server" ) ;
9
10
@@ -27,6 +28,28 @@ const hostname = process.env.NODE_ENV == "production" ? os.hostname() : "localho
27
28
28
29
let socketIoPortOffset : number = 0 ;
29
30
31
+ passport . use ( new DigestStrategy ( { qop : 'auth' } ,
32
+ function ( username : any , done : any ) {
33
+ if ( username === Configuration . authUser ) {
34
+ return done ( null , { id : 1 , name : username } , Configuration . authPassword ) ;
35
+ } else {
36
+ return done ( "Invalid user" , null ) ;
37
+ }
38
+ } ,
39
+ function ( params : any , done : any ) {
40
+ // validate nonce as necessary
41
+ done ( null , true )
42
+ }
43
+ ) ) ;
44
+
45
+ passport . serializeUser ( function ( user : any , done : any ) {
46
+ done ( null , user . id ) ;
47
+ } ) ;
48
+
49
+ passport . deserializeUser ( function ( id : any , done : any ) {
50
+ done ( null , { id : 1 , name : Configuration . authUser } ) ;
51
+ } ) ;
52
+
30
53
startExpressServer ( ) ;
31
54
32
55
function startExpressServer ( ) {
@@ -48,14 +71,20 @@ function startExpressServer() {
48
71
49
72
app = express ( ) ;
50
73
74
+ if ( Configuration . authRequired ) {
75
+ app . use ( passport . initialize ( ) ) ;
76
+
77
+ app . get ( "/" , passport . authenticate ( 'digest' , { session : false } ) , ( request : any , response : any , next : any ) => {
78
+ next ( ) ;
79
+ } ) ;
80
+ }
81
+
51
82
app . use ( express . static ( rootPath ) ) ;
52
83
53
84
app . post ( "/graphql" , proxy ( apiUri + "/graphql" ) ) ;
54
85
55
86
app . use ( "/thumbnail" , proxy ( apiUri + "/thumbnail" ) ) ;
56
87
57
- // app.use("/thumbnailData", proxy(apiUri + "/thumbnailData"));
58
-
59
88
app . use ( `${ Configuration . internalApiBase } serverConfiguration` , serverConfiguration ) ;
60
89
61
90
app . use ( "/" , ( req , res ) => {
@@ -126,12 +155,9 @@ function devServer() {
126
155
} ,
127
156
"/thumbnail" : {
128
157
target : apiUri
129
- } ,
130
- // "/thumbnailData": {
131
- // target: apiUri
132
- // }
158
+ }
133
159
} ,
134
- contentBase : path . resolve ( path . join ( __dirname , ".." , "public" ) ) ,
160
+ contentBase : path . resolve ( path . join ( __dirname , ".." ) ) ,
135
161
disableHostCheck : true ,
136
162
publicPath : webpackConfig . output . publicPath ,
137
163
// hot: true,
0 commit comments