-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
48 lines (37 loc) · 1.11 KB
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import express, { Application } from 'express';
import cors from 'cors';
import fs from 'fs'
import util from 'util';
import bindata from './bindata.json'
// interface ICardObject {
// 'BIN': number, 'ISSUER': string, 'CARDNAME': string, 'CARDTYPE': string, 'CARDOWNERTYPE': number
// }
class App {
public application: Application;
constructor() {
this.application = express();
}
}
const app = new App().application;
app.use(cors());
app.all('/*', function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'X-Requested-With');
next();
});
app.listen(3001,async () => {
console.info('✅ Start korea-card-bin-api server✅');
});
//read data when server start
const data = JSON.parse(JSON.stringify(bindata))
app.get('/', function(req, res) {
res.redirect('https://github.com/cokia/korea-card-bin-api');
});
app.get('/api/:binNumber', async function(req,res) {
//@ts-ignore
const result = (data.filter(x => x["BIN"] === parseInt(req.params.binNumber)))[0];
if (result == undefined){
res.status(404).send({})
}
res.status(200).send(result);
});