mirror of
https://codeberg.org/angestoepselt/homepage.git
synced 2025-05-24 14:46:16 +00:00
Add backend boilerplate
This commit is contained in:
parent
bc9cffefca
commit
d45e2d141e
1 changed files with 43 additions and 0 deletions
43
src/backend.mjs
Normal file
43
src/backend.mjs
Normal 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();
|
||||||
Loading…
Add table
Reference in a new issue