import { Request , Response } from 'express' ; import express from 'express' ; const router = express . Router ( ) ; import profileWidget from '../../src/widgets/profile' ; import errorWidget from '../../src/widgets/error' ; const githubUsernameRegex = require ( "github-username-regex" ) ; router . get ( '/' , function ( req , res ) { const { username , data } = req . query ; res . setHeader ( 'Content-Type' , 'image/svg+xml' ) ; if ( username === undefined || username === null ) { res . send ( errorWidget ( 'Profile' , '-25%' , 'Username is undefined!' , '-26%' ) ) ; return ; } if ( ! githubUsernameRegex . test ( username ) ) { res . send ( errorWidget ( 'Profile' , '-25%' , 'Username is invalid!' , '-22%' ) ) ; return ; } if ( data === undefined || data === null ) { res . send ( errorWidget ( 'Profile' , '-25%' , 'Data option is missing!' , '-25%' ) ) ; return ; } profileWidget ( String ( username ) , String ( data ) ) . then ( ( response ) => { if ( response === undefined || response === null ) { res . send ( errorWidget ( 'Profile' , '-25%' , 'GitHub API-call error!' , '-24%' ) ) ; } else { res . send ( response ) ; } } ) ; } ) ; export default router ;