'use strict';
const express = require("express");
const cookieParser = require("cookie-parser");
const bodyParser = require('body-parser');
const cors = require('cors');

var server = express();
server.use(express.static('public'));
server.use(cors());
server.use(bodyParser.json());
server.use(bodyParser.urlencoded({ extended: false }));
server.use(cookieParser());

const port = process.env.PORT || 1337;

server.get('/', function (req, res) {
	
});

server.post('/generate', function (req, res) {
	let taskID = Date.now.toString(16);
	res.cookie("taskID", taskID, {maxAge: 900000, httpOnly: true});
	res.end('<script src="./js/getImage.js"></script><script>setInterval(function() {detectImage("16");}, 5000);</script>');
});

server.get('/success', function (req, res) {
	let taskID = req.query.taskID;

	res.end();
});

server.listen(port);
