2023-04-11 21:05:35 +02:00
|
|
|
const express = require('express');
|
|
|
|
|
2023-04-29 13:59:36 +02:00
|
|
|
const getSuggestedEndpoint = require('./endpoint_handlers/suggested.js');
|
|
|
|
const getMetadataEndpoint = require('./endpoint_handlers/metadata.js');
|
|
|
|
const getOccasionsEndpoint = require('./endpoint_handlers/occasions.js');
|
|
|
|
const getLicenceInfo = require('./endpoint_handlers/licenseinfo.js');
|
|
|
|
|
2023-04-11 21:05:35 +02:00
|
|
|
// Read the port from the environment if possible
|
|
|
|
const port = process.env.PORT || 3000;
|
|
|
|
|
|
|
|
const server = express();
|
|
|
|
|
|
|
|
// Set up the static directory to server cssa and other assets
|
|
|
|
server.use('/static', express.static('static'));
|
|
|
|
|
2023-04-29 13:59:36 +02:00
|
|
|
server.use(express.json());
|
|
|
|
server.use(
|
|
|
|
express.urlencoded({
|
|
|
|
extended: true,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2023-04-11 21:05:35 +02:00
|
|
|
// Root path serves index
|
|
|
|
server.get('/', (req, res) => {
|
|
|
|
res.sendFile(__dirname + '/html/index.html');
|
|
|
|
});
|
|
|
|
|
2023-04-29 13:59:36 +02:00
|
|
|
// Set up API endpoints
|
|
|
|
server.post('/suggested', getSuggestedEndpoint)
|
|
|
|
server.post('/metadata', getMetadataEndpoint)
|
|
|
|
server.post('/occasions', getOccasionsEndpoint)
|
|
|
|
server.post('/licenseinfo', getLicenceInfo)
|
|
|
|
|
2023-04-11 21:05:35 +02:00
|
|
|
// Listen and provide feedback
|
|
|
|
server.listen(port, () => {
|
2024-11-05 22:41:56 +01:00
|
|
|
console.log(`Server running on http://localhost:${port}`);
|
2023-04-29 13:59:36 +02:00
|
|
|
});
|