const express = require('express');
const config = require('./config');

var MongoClient = require ('mongodb').MongoClient;
var ObjectID = require ('mongodb').ObjectID;

const app = express();

app.get('/list', (req,res)=>{
    res.header ('Access-Control-Allow-Origin', '*');
    db.collection('expired_list').find({}).toArray((err,result)=>{
        if (err){
            res.send(JSON.stringify(null));
        }else{
            res.send(JSON.stringify(result));
        }
    });
});

MongoClient.connect (config.databaseURL).then (database => {
    db = database;
    app.listen(config.PORT, ()=>{console.log('Server running on port ' + config.PORT)});
});