import { SERVER_HELLO_ENDPOINT } from 'common/lib/constants' ; import express from 'express' ; import cors from 'cors' ; import bodyParser from 'body-parser' ; import { getAccessTokenOrErrorResponse } from './auth' ; if ( process . env . NODE_ENV !== 'production' ) { require ( 'dotenv' ) . load ( ) ; } const app = express ( ) ; const port = process . env . PORT || 5000 ; app . use ( cors ( ) ) ; app . use ( bodyParser . json ( ) ) ; app . get ( '/' + SERVER_HELLO_ENDPOINT . path , ( _req , res ) => { res . contentType ( 'application/json' ) . status ( 200 ) . send ( SERVER_HELLO_ENDPOINT . payload ) ; } ) ; app . post ( '/auth' , async ( req , res ) => { const { code , state } = req . body ; let responsePayload = await getAccessTokenOrErrorResponse ( { code , state , } ) ; res . contentType ( 'application/json' ) . status ( 200 ) . send ( responsePayload ) ; } ) ; app . listen ( port , ( ) => console . log ( `Listening on port ${ port }` ) ) ;