1
1
import { Express , Request , Response , NextFunction } from 'express' ;
2
2
import { handleGoogleAuth } from '../controllers/auth.controller' ;
3
- import { retrieveSchema , saveSchema , userRegistration , verifyUser } from '../controllers/user.controller' ;
3
+ import {
4
+ retrieveSchema ,
5
+ saveSchema ,
6
+ userRegistration ,
7
+ verifyUser ,
8
+ } from '../controllers/user.controller' ;
4
9
import { postgresRouter } from './postgres.router' ;
5
10
import mysqlRouter from './mysql.router' ;
6
11
import session from 'express-session' ;
7
- declare module " express-session" {
12
+ declare module ' express-session' {
8
13
interface SessionData {
9
14
user : string ;
10
15
}
11
16
}
12
- import connectRedis from 'connect-redis'
13
- import dotenv from 'dotenv'
17
+ import connectRedis from 'connect-redis' ;
18
+ import dotenv from 'dotenv' ;
14
19
dotenv . config ( ) ;
15
- import Redis from 'ioredis'
16
- import { getCurrentUser } from '../service/session.service'
20
+ import Redis from 'ioredis' ;
21
+ import { getCurrentUser } from '../service/session.service' ;
17
22
import path from 'path' ;
18
23
19
-
20
- const client_url = process . env . NODE_ENV === 'development' ? process . env . DEV_CLIENT_ENDPOINT : process . env . CLIENT_ENDPOINT
24
+ const client_url =
25
+ process . env . NODE_ENV === 'development'
26
+ ? process . env . DEV_CLIENT_ENDPOINT
27
+ : process . env . CLIENT_ENDPOINT ;
21
28
22
29
const routes = async ( app : Express ) => {
23
- // setup UpStash client and Redis store
30
+ // setup UpStash client and Redis store
24
31
const RedisStore = connectRedis ( session ) ;
25
32
26
- const client = new Redis ( `rediss://:${ process . env . REDIS_PASSWORD } @${ process . env . REDIS_URL } :${ process . env . REDIS_PORT } ` )
33
+ const client = new Redis (
34
+ `rediss://:${ process . env . REDIS_PASSWORD } @${ process . env . REDIS_URL } :${ process . env . REDIS_PORT } `
35
+ ) ;
27
36
28
37
// set session cookie
29
- app . use ( session ( {
30
- store : new RedisStore ( { client } ) ,
31
- secret : process . env . REDIS_SECRET as string ,
32
- resave : false ,
33
- saveUninitialized : true ,
34
- cookie : {
35
- secure : process . env . ENVIRONMENT === 'production' ? true : 'auto' ,
36
- maxAge : 24 * 60 * 60 * 1000 ,
37
- sameSite : 'lax' ,
38
- }
39
- } ) )
38
+ app . use (
39
+ session ( {
40
+ store : new RedisStore ( { client } ) ,
41
+ secret : process . env . REDIS_SECRET as string ,
42
+ resave : false ,
43
+ saveUninitialized : true ,
44
+ cookie : {
45
+ secure : process . env . ENVIRONMENT === 'production' ? true : 'auto' ,
46
+ maxAge : 24 * 60 * 60 * 1000 ,
47
+ sameSite : 'lax' ,
48
+ } ,
49
+ } )
50
+ ) ;
40
51
41
52
app . get ( '/api/healthcheck' , ( req : Request , res : Response ) => res . sendStatus ( 200 ) ) ;
42
53
@@ -58,13 +69,13 @@ const routes = async (app: Express) => {
58
69
59
70
app . use ( '/api/logout' , ( req : Request , res : Response ) => {
60
71
req . session . destroy ( ( err ) => {
61
- if ( err ) console . log ( 'Error destroying session:' , err )
72
+ if ( err ) console . log ( 'Error destroying session:' , err ) ;
62
73
else {
63
- console . log ( 'Succesfully destroyed session' )
64
- return res . redirect ( `${ client_url } /` )
74
+ console . log ( 'Succesfully destroyed session' ) ;
75
+ return res . redirect ( `/` ) ;
65
76
}
66
77
} ) ;
67
- } )
78
+ } ) ;
68
79
69
80
app . get ( '/*' , ( req , res ) => {
70
81
res . sendFile ( path . join ( __dirname , '../../dist/index.html' ) ) ;
@@ -80,6 +91,6 @@ const routes = async (app: Express) => {
80
91
const errorObj = Object . assign ( { } , defaultErr , err ) ;
81
92
return res . status ( errorObj . status ) . json ( errorObj . message ) ;
82
93
} ) ;
83
- }
94
+ } ;
84
95
85
- export default routes ;
96
+ export default routes ;
0 commit comments