Merge branch 'feature/integrate-playwright'
This commit is contained in:
27
routes/api.js
Normal file
27
routes/api.js
Normal file
@@ -0,0 +1,27 @@
|
||||
// import router from express
|
||||
var express = require('express');
|
||||
const PlaywrightService = require('../services/PlaywrightService');
|
||||
var router = express.Router();
|
||||
|
||||
/**
|
||||
* GET run accessibility test on domain
|
||||
* Only works for homepage
|
||||
* // TODO: Crawl site map and queue all pages
|
||||
*/
|
||||
router.get('/test/accessibility/:domain', function(req, res) {
|
||||
req.setTimeout(5000000000000);
|
||||
const domain = req.params.domain; // Get the domain from the request parameters
|
||||
|
||||
const playwrightService = new PlaywrightService(domain);
|
||||
|
||||
// Call the runAccessibilityTest method
|
||||
playwrightService.getAccessibilityResults().then(results => {
|
||||
// Send the results as a JSON response
|
||||
res.json(results);
|
||||
}).catch(err => {
|
||||
// Handle any errors that occur during the test
|
||||
res.status(500).json({ error: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
70
routes/sites.js
Normal file
70
routes/sites.js
Normal file
@@ -0,0 +1,70 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const SiteModel = require('../models/SiteModel');
|
||||
const siteModel = new SiteModel();
|
||||
|
||||
/**
|
||||
* GET sites listing.
|
||||
*
|
||||
* Returns a list of all sites in JSON format.
|
||||
*/
|
||||
router.get('/', async function(req, res, next) {
|
||||
const sites = await siteModel.getAll();
|
||||
|
||||
res.json(sites);
|
||||
});
|
||||
|
||||
/**
|
||||
* GET site by ID.
|
||||
*
|
||||
* Returns a specific site by its ID in JSON format.
|
||||
*/
|
||||
router.get('/:id', async function(req, res, next) {
|
||||
const siteId = req.params.id;
|
||||
|
||||
const site = await siteModel.getById(siteId);
|
||||
|
||||
if (!site) {
|
||||
return res.status(404).send('Site not found');
|
||||
} else {
|
||||
res.json(site);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* POST create a new site.
|
||||
*
|
||||
* Creates a new site with the provided domain name.
|
||||
*
|
||||
* // TODO: Implement validation for domain name format
|
||||
* // TODO: Implement error handling for duplicate domains
|
||||
* // TODO: Ability to add additional site properties (e.g., name, description)
|
||||
*/
|
||||
router.post('/add/:domain', function(req, res, next) {
|
||||
const domain = req.params.domain;
|
||||
|
||||
const newSite = siteModel.insert(domain);
|
||||
|
||||
if (!newSite) {
|
||||
return res.status(400).send('Error creating site');
|
||||
} else {
|
||||
res.status(201).json(newSite);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* PUT update an existing site.
|
||||
*
|
||||
* Updates an existing site with the provided ID and new data.
|
||||
*/
|
||||
|
||||
// TODO: Implement update functionality
|
||||
|
||||
/**
|
||||
* DELETE remove a site by ID.
|
||||
*/
|
||||
|
||||
// TODO: Implement delete functionality
|
||||
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user