Add backend boilerplate

This commit is contained in:
Yannik Rödel 2021-10-07 16:25:15 +02:00
parent bc9cffefca
commit d45e2d141e

43
src/backend.mjs Normal file
View file

@ -0,0 +1,43 @@
import express from 'express';
/**
* Get Zammad access credentials and verify the connection.
* @param {ReturnType<express>} app
*/
function initializeZammad(app) {
console.info('Checking connection to Zammad...');
let url = process.env.ZAMMAD_URL || '';
if (url === '') {
throw new Error(
'Could not find the Zammad URL to connect to. Make sure it is provided using the ZAMMAD_URL environment variable. It should point to the root URL of the Zammad installation.'
);
}
url = url.replace(/\/$/, '');
const token = process.env.ZAMMAD_TOKEN || '';
if (token === '') {
throw new Error(
'Could not find authentication credentials for Zammad. Make sure the token is provided using the ZAMMAD_TOKEN environment variable.'
);
}
app.set('zammad url', url);
app.set('zammad token', token);
// TODO Verify the connection
}
function run() {
const app = express();
initializeZammad(app);
app.post('/kontakt', (req, res) => {});
const port = parseInt(process.env.LISTEN_PORT || '3000');
return app.listen(port, () => {
console.log(`Server listening at http://localhost:${port}...`);
});
}
run();