43 lines
1.4 KiB
JavaScript
43 lines
1.4 KiB
JavaScript
|
|
require('dotenv').config({ quiet: true });
|
|
|
|
const path = require('path');
|
|
const express = require('express');
|
|
const { createBoardService } = require('./boardService');
|
|
const { createRoutes } = require('./routes');
|
|
|
|
const { CLIENT_ID, CLIENT_SECRET, TECHNICIAN_NAMES, STATUS_NAMES } = process.env;
|
|
const PORT = process.env.PORT || 3000; // default 3000
|
|
|
|
if (!CLIENT_ID || !CLIENT_SECRET) {
|
|
console.error('Client id and secret missing from .env');
|
|
process.exit(1);
|
|
}
|
|
|
|
const technicians = (TECHNICIAN_NAMES ? TECHNICIAN_NAMES.split(',') : []).map(t => t.trim()).filter(Boolean);
|
|
const statuses = (STATUS_NAMES ? STATUS_NAMES.split(',') : []).map(s => s.trim()).filter(Boolean);
|
|
const statusSet = new Set(statuses.map(s => s.toLowerCase()));
|
|
|
|
const WINDOW_MINUTES = 10; // how far back the server looks in minutes
|
|
const CHECK_MINUTES = 1; // how often the server checks for new tickets in minutes
|
|
|
|
const app = express();
|
|
|
|
//creates the board service with the config specified
|
|
const boardService = createBoardService({
|
|
clientId: CLIENT_ID,
|
|
clientSecret: CLIENT_SECRET,
|
|
technicians,
|
|
statusSet,
|
|
windowMinutes: WINDOW_MINUTES,
|
|
checkMinutes: CHECK_MINUTES
|
|
});
|
|
|
|
app.use(express.static(path.join(__dirname, 'public')));
|
|
|
|
app.use('/api', createRoutes(boardService));
|
|
|
|
//starts listening on port specified
|
|
app.listen(PORT, () => {
|
|
console.log(`Open http://localhost:${PORT}`);
|
|
}); |