@@ -3,7 +3,8 @@ import * as os from "os";
33const express = require ( "express" ) ;
44import * as http from "http" ;
55import * as proxy from "express-http-proxy" ;
6-
6+ const passport = require ( "passport" ) ;
7+ const DigestStrategy = require ( "passport-http" ) . DigestStrategy ;
78
89const debug = require ( "debug" ) ( "pipeline-api:server" ) ;
910
@@ -27,6 +28,28 @@ const hostname = process.env.NODE_ENV == "production" ? os.hostname() : "localho
2728
2829let socketIoPortOffset : number = 0 ;
2930
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+
3053startExpressServer ( ) ;
3154
3255function startExpressServer ( ) {
@@ -48,14 +71,20 @@ function startExpressServer() {
4871
4972 app = express ( ) ;
5073
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+
5182 app . use ( express . static ( rootPath ) ) ;
5283
5384 app . post ( "/graphql" , proxy ( apiUri + "/graphql" ) ) ;
5485
5586 app . use ( "/thumbnail" , proxy ( apiUri + "/thumbnail" ) ) ;
5687
57- // app.use("/thumbnailData", proxy(apiUri + "/thumbnailData"));
58-
5988 app . use ( `${ Configuration . internalApiBase } serverConfiguration` , serverConfiguration ) ;
6089
6190 app . use ( "/" , ( req , res ) => {
@@ -126,12 +155,9 @@ function devServer() {
126155 } ,
127156 "/thumbnail" : {
128157 target : apiUri
129- } ,
130- // "/thumbnailData": {
131- // target: apiUri
132- // }
158+ }
133159 } ,
134- contentBase : path . resolve ( path . join ( __dirname , ".." , "public" ) ) ,
160+ contentBase : path . resolve ( path . join ( __dirname , ".." ) ) ,
135161 disableHostCheck : true ,
136162 publicPath : webpackConfig . output . publicPath ,
137163 // hot: true,
0 commit comments