var express = require('express');
var config = require('./config');
var app = express();

app.set('view engine', 'ejs');
app.set('views', __dirname + '/views');

app.use(function(req, res, next) {
  var header = {
    'Access-Control-Allow-Origin': '*'
  }
  for (var i in req.headers) {
    if (i.toLowerCase().substr(0, 15) == 'access-control-') {
      header[i.replace(/-request-/g, '-allow-')] = req.headers[i];
    }
  }
  res.header(header);
  next();
});

app.use('/barcode', require('./modules/barcode'));
app.use('/printer', require('./modules/printer'));
app.use('/idcard', require('./modules/idcard'));
app.use('/rfid', require('./modules/rfid'));

app.listen(config.port);
