@@ -2,7 +2,7 @@ import * as path from "path";
22import * as winston from "winston" ;
33import * as http from "http" ;
44import * as https from "https" ;
5- import * as express from "express" ;
5+ import * as express from "express" ;
66import * as compression from "compression" ;
77import * as bodyParser from "body-parser" ;
88import * as cookieParser from "cookie-parser" ;
@@ -18,9 +18,9 @@ import { Config } from "./Config";
1818
1919export class WebServer {
2020 private static _logger : winston . Logger ;
21- private static app :express . Express ;
21+ private static app : express . Express ;
2222
23- static async configure ( logger : winston . Logger , baseurl :string ) : Promise < http . Server > {
23+ static async configure ( logger : winston . Logger , baseurl : string ) : Promise < http . Server > {
2424 this . _logger = logger ;
2525
2626 this . app = express ( ) ;
@@ -34,33 +34,33 @@ export class WebServer {
3434 } ) ) ;
3535 this . app . use ( flash ( ) ) ;
3636
37-
37+
3838 // Add headers
3939 this . app . use ( function ( req , res , next ) {
4040
4141 // Website you wish to allow to connect
4242 res . setHeader ( 'Access-Control-Allow-Origin' , '*' ) ;
43-
43+
4444 // Request methods you wish to allow
4545 res . setHeader ( 'Access-Control-Allow-Methods' , 'GET, POST, OPTIONS, PUT, PATCH, DELETE' ) ;
46-
46+
4747 // Request headers you wish to allow
4848 res . setHeader ( 'Access-Control-Allow-Headers' , 'X-Requested-With,content-type' ) ;
49-
49+
5050 // Set to true if you need the website to include cookies in the requests sent
5151 // to the API (e.g. in case you use sessions)
5252 res . setHeader ( 'Access-Control-Allow-Credentials' , "true" ) ;
53-
53+
5454 // Pass to next layer of middleware
5555 next ( ) ;
5656 } ) ;
5757 this . app . use ( "/" , express . static ( path . join ( __dirname , "/public" ) ) ) ;
5858
5959 await LoginProvider . configure ( this . _logger , this . app , baseurl ) ;
6060 await SamlProvider . configure ( this . _logger , this . app , baseurl ) ;
61- var server :http . Server = null ;
61+ var server : http . Server = null ;
6262 if ( Config . tls_crt != '' && Config . tls_key != '' ) {
63- var options :any = {
63+ var options : any = {
6464 cert : Config . tls_crt ,
6565 key : Config . tls_key
6666 } ;
@@ -70,20 +70,27 @@ export class WebServer {
7070 key : Buffer . from ( Config . tls_key , 'base64' ) . toString ( 'ascii' )
7171 } ;
7272 }
73- var ca :string = Config . tls_ca ;
74- if ( ca !== "" ) {
75- if ( ca . indexOf ( "---" ) === - 1 ) {
73+ var ca : string = Config . tls_ca ;
74+ if ( ca !== "" ) {
75+ if ( ca . indexOf ( "---" ) === - 1 ) {
7676 ca = Buffer . from ( Config . tls_ca , 'base64' ) . toString ( 'ascii' ) ;
7777 }
7878 options . ca = ca ;
7979 // options.cert += "\n" + ca;
8080 }
81- if ( Config . tls_passphrase !== "" ) {
81+ if ( Config . tls_passphrase !== "" ) {
8282 // options.cert = [options.cert, Config.tls_passphrase];
8383 // options.key = [options.key, Config.tls_passphrase];
8484 options . passphrase = Config . tls_passphrase ;
8585 }
8686 server = https . createServer ( options , this . app ) ;
87+
88+ var redirapp = express ( ) ;
89+ var _http = http . createServer ( redirapp ) ;
90+ redirapp . get ( '*' , function ( req , res ) {
91+ res . redirect ( 'https://' + req . headers . host + req . url ) ;
92+ } )
93+ _http . listen ( 80 ) ;
8794 } else {
8895 server = http . createServer ( this . app ) ;
8996 }
0 commit comments