const generateCover = require("./lib");
var express = require('express');
var path = require('path');

var app = express();


app.use('/assets',express.static(__dirname + '/assets'));
app.use('/lib',express.static(__dirname + '/lib'));


app.get("/generate-cover", async (req, res) => {
  
    const coverStream = await generateCover({
      title: "BreadnBudder Gaming | HOME",
      avatarUrl:__dirname + '/assets/img/Logo.Border.FOR.WEB.png',
      name: "BreadnBudder Gaming"
    });

    res.statusCode = 200;
    res.setHeader("Content-Type", "image/png");
    res.setHeader("Content-Control", "public, max-age=31536000");

    coverStream.pipe(res);
});

//for /index page
app.get('/', function(request,response){
	response.sendFile('index.html',{root:path.join(__dirname,'./')});
});

app.get('/index.html', function(request,response){
	response.sendFile('index.html',{root:path.join(__dirname,'./')});
});

app.listen(3000,function(){
	console.log('Listening at port 3000...');
});

module.exports = app;