1
- // @ts -nocheck File not migrated fully to TS
2
1
import fs from 'fs' ;
3
2
import path from 'path' ;
4
3
import expressStaticGzip from 'express-static-gzip' ;
5
4
import express from 'express' ;
6
5
import passport from 'passport' ;
7
6
import cookieParser from 'cookie-parser' ;
8
7
import morgan from 'morgan' ;
9
- import type { Router } from 'express' ;
8
+ import type { ErrorRequestHandler , Router } from 'express' ;
10
9
11
- import { getConfig , getClientConfig } from './config' ;
10
+ import { getConfig } from './config' ;
12
11
import { CONTEXT_PATH } from './consts' ;
13
12
import LoggerHandler from './handler/LoggerHandler' ;
14
- import { getMode } from './serverSettings' ;
15
13
import { getResourcePath } from './utils' ;
16
14
17
15
import getCookieStrategy from './auth/CookieStrategy' ;
@@ -46,13 +44,13 @@ const app = express();
46
44
47
45
app . use ( morgan ( 'short' , { stream : LoggerHandler . getStream ( 'Express' ) } ) ) ;
48
46
49
- app . all ( '/' , ( request , response ) => {
47
+ app . all ( '/' , ( _request , response ) => {
50
48
logger . info ( `Redirecting to "${ contextPath } ".` ) ;
51
49
response . redirect ( contextPath ) ;
52
50
} ) ;
53
51
54
52
// For dev purposes
55
- app . use ( contextPath , ( req , res , next ) => {
53
+ app . use ( contextPath , ( _req , res , next ) => {
56
54
// Setting access control allow origin headers
57
55
res . setHeader ( 'Access-Control-Allow-Origin' , 'http://localhost:4000' ) ;
58
56
// Request methods you wish to allow
@@ -64,7 +62,7 @@ app.use(contextPath, (req, res, next) => {
64
62
) ;
65
63
// Set to true if you need the website to include cookies in the requests sent
66
64
// to the API (e.g. in case you use sessions)
67
- res . setHeader ( 'Access-Control-Allow-Credentials' , true ) ;
65
+ res . setHeader ( 'Access-Control-Allow-Credentials' , ' true' ) ;
68
66
69
67
next ( ) ;
70
68
} ) ;
@@ -83,11 +81,11 @@ app.use(passport.initialize());
83
81
app . use (
84
82
`${ contextPath } /appData` ,
85
83
authenticateWithCookie ,
86
- expressStaticGzip ( path . resolve ( __dirname , '../dist/appData' ) , { indexFromEmptyFile : false } )
84
+ expressStaticGzip ( path . resolve ( __dirname , '../dist/appData' ) , { index : false } )
87
85
) ;
88
86
89
87
const translationsOverrides = 'overrides.json' ;
90
- app . use ( `${ contextPath } /userData/${ translationsOverrides } ` , ( req , res ) => {
88
+ app . use ( `${ contextPath } /userData/${ translationsOverrides } ` , ( _req , res ) => {
91
89
const overridesPath = getResourcePath ( translationsOverrides , true ) ;
92
90
if ( fs . existsSync ( overridesPath ) ) res . sendFile ( overridesPath ) ;
93
91
else res . send ( { } ) ;
@@ -97,7 +95,7 @@ app.use(
97
95
`${ contextPath } /userData` ,
98
96
authenticateWithCookie ,
99
97
expressStaticGzip ( getResourcePath ( '' , true ) , {
100
- indexFromEmptyFile : false
98
+ index : false
101
99
} )
102
100
) ;
103
101
// API Routes with authentication
@@ -149,8 +147,7 @@ app.get('*', (request, response) => {
149
147
* NOTE: error handlers must have 4 parameters, even if the last one is unused
150
148
* @see https://expressjs.com/en/guide/error-handling.html
151
149
*/
152
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
153
- app . use ( ( err , req , res , next ) => {
150
+ const errorHandler : ErrorRequestHandler = ( err , _req , res , _next ) => {
154
151
logger . error ( 'Error has occured ' , err ) ;
155
152
156
153
let { message } = err ;
@@ -159,6 +156,7 @@ app.use((err, req, res, next) => {
159
156
}
160
157
161
158
res . status ( err . status || 404 ) . send ( { message : message || err } ) ;
162
- } ) ;
159
+ } ;
160
+ app . use ( errorHandler ) ;
163
161
164
162
export default app ;
0 commit comments