feat: wire modules together into the running server
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013gwc3aCiyQxmCWQke8RvEz
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
const path = require('node:path');
|
||||
const {
|
||||
openDb, listProducts, addProduct, deleteProduct,
|
||||
recordCheckSuccess, recordCheckFailure,
|
||||
} = require('./src/db');
|
||||
const { fetchAndExtractPrice } = require('./src/scraper');
|
||||
const { createTransport, sendPriceChangeEmail } = require('./src/mailer');
|
||||
const { checkAllProducts } = require('./src/checkProducts');
|
||||
const { start: startScheduler } = require('./src/scheduler');
|
||||
const { createApp } = require('./src/app');
|
||||
|
||||
const PORT = process.env.PORT || 3000;
|
||||
const DB_PATH = process.env.DB_PATH || path.join(__dirname, 'data', 'korting.db');
|
||||
|
||||
const db = openDb(DB_PATH);
|
||||
const transport = createTransport(process.env);
|
||||
|
||||
function runCheck() {
|
||||
const products = listProducts(db);
|
||||
const deps = {
|
||||
fetchAndExtractPrice,
|
||||
sendMail: (payload) => sendPriceChangeEmail(transport, {
|
||||
from: process.env.SMTP_FROM,
|
||||
to: process.env.NOTIFY_EMAIL,
|
||||
...payload,
|
||||
}),
|
||||
recordCheckFailure: (id, status) => recordCheckFailure(db, id, status),
|
||||
recordCheckSuccess: (id, data) => recordCheckSuccess(db, id, data),
|
||||
now: () => new Date().toISOString(),
|
||||
};
|
||||
return checkAllProducts(products, deps);
|
||||
}
|
||||
|
||||
startScheduler(runCheck);
|
||||
|
||||
const app = createApp({
|
||||
listProducts: () => listProducts(db),
|
||||
addProduct: (data) => addProduct(db, data),
|
||||
deleteProduct: (id) => deleteProduct(db, id),
|
||||
checkAllProducts: runCheck,
|
||||
authUser: process.env.BASIC_AUTH_USER,
|
||||
authPass: process.env.BASIC_AUTH_PASS,
|
||||
});
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Korting draait op poort ${PORT}`);
|
||||
});
|
||||
Reference in New Issue
Block a user