1- /** @format */
21require ( "dotenv" ) . config ( ) ;
3- import { startServer } from "./server" ;
2+ import express = require( "express" ) ;
3+ import cors = require( "cors" ) ;
4+ import { json , urlencoded } from "body-parser" ;
5+ import session = require( "express-session" ) ;
6+ import { env_config } from "./config" ;
7+ import { Express } from "express"
8+ var cookieParser = require ( "cookie-parser" )
9+ // Router Imports
10+ const links_router = require ( "./routes/links" )
11+ const survey_router = require ( "./routes/survey" )
12+ const auth_router = require ( "./routes/auth" )
13+ const encrypt_router = require ( "./routes/encrypt" )
14+ const validate_router = require ( "./routes/validation" )
415
5- async function main ( ) : Promise < void > {
6- // should be updated to Load CSV from URL (we can hard code that URL for now, and can deal with dynamic coding later)
7- startServer ( ) ;
8- }
916
10- main ( ) ;
17+ export async function create_app ( ) :Promise < Express > {
18+ const app = express ( )
19+ app . use ( cors ( ) )
20+ app . use (
21+ session ( {
22+ secret : env_config . TOKEN_KEY , // just a long random string
23+ resave : false ,
24+ saveUninitialized : true ,
25+ } )
26+ ) ;
27+
28+ app . set ( "view engine" , "pug" ) ;
29+ app . use ( express . static ( "public" ) ) ; // More info on this: http://expressjs.com/en/starter/static-files.html
30+ app . use ( json ( ) ) ; // for parsing application/json
31+ app . use ( urlencoded ( { extended : true } ) ) ; // for parsing url
32+ app . use ( cookieParser ( ) )
33+
34+ /** ROUTES */
35+ app . use ( "/" , survey_router )
36+ app . use ( "/" , links_router )
37+ app . use ( "/" , auth_router )
38+ app . use ( "/" , encrypt_router )
39+ app . use ( "/validate" , validate_router )
40+
41+ return app
42+ }
0 commit comments