@@ -4,9 +4,16 @@ var app = express();
44const atob = require ( 'atob' ) ;
55// const KEY = require('./key');
66const Base64 = require ( 'base-64' ) ;
7+ const { Sequelize } = require ( 'sequelize' ) ;
78const KEY = process . env . GITHUB_TOKEN
89app . use ( cors ( ) )
910
11+ const sequelize = new Sequelize ( 'sqlite::memory:' , {
12+ dialect : 'sqlite' ,
13+ storage : 'test.sqlite'
14+ } )
15+
16+
1017
1118const {
1219 default : Axios
@@ -80,23 +87,29 @@ app.get('/add-sha/:sha', (req, res) => {
8087 Axios . get ( "https://api.github.com/repos/ujjwal-kr-data/ip-data/contents/" + req . params . sha , {
8188 headers : { 'Authorization' : "token " + KEY }
8289 } ) . then ( result => {
83- const contentSHA = result . data . sha ;
84- let visits = Base64 . decode ( result . data . content )
85- let newVisit = Base64 . encode ( parseInt ( visits ) + 1 )
86- Axios . put ( "https://api.github.com/repos/ujjwal-kr-data/ip-data/contents/" + req . params . sha , {
87- message : "UPDATED COUNT" ,
88- sha : contentSHA ,
89- content : newVisit
90- } , { headers : { 'Authorization' : "token " + KEY } } ) . then ( done => {
91- res . json ( { visits : Base64 . decode ( newVisit ) } )
90+ const contentSHA = result . data . sha ;
91+ let visits = Base64 . decode ( result . data . content )
92+ let newVisit = Base64 . encode ( parseInt ( visits ) + 1 )
93+ Axios . put ( "https://api.github.com/repos/ujjwal-kr-data/ip-data/contents/" + req . params . sha , {
94+ message : "UPDATED COUNT" ,
95+ sha : contentSHA ,
96+ content : newVisit
97+ } , { headers : { 'Authorization' : "token " + KEY } } ) . then ( done => {
98+ res . json ( { visits : Base64 . decode ( newVisit ) } )
9299 } )
93- . catch ( e => console . log ( e ) )
100+ . catch ( e => console . log ( e ) )
94101 } )
95- . catch ( e => { console . log ( e ) } )
102+ . catch ( e => { console . log ( e ) } )
96103 } )
97104} )
98105
99106const port = process . env . PORT || 4000 ;
100- app . listen ( port , ( ) => {
107+ app . listen ( port , async ( ) => {
101108 console . log ( `Waiting on port for someone :) ${ port } ` ) ;
109+ try {
110+ await sequelize . authenticate ( ) ;
111+ console . log ( 'Connection has been established successfully.' ) ;
112+ } catch ( error ) {
113+ console . error ( 'Unable to connect to the database:' , error ) ;
114+ }
102115} ) ;
0 commit comments