我正在使用Angular Fullstack创建一个Web应用程序。我创建了大量自定义端点。除了我刚创建的这个新端点外,所有这些似乎都有用。我已经尝试重新组织我的端点,没有新的端点可以工作。
'use strict';
var express = require('express');
var controller = require('./proctoring.controller');
var router = express.Router();
router.get('/', controller.index);
router.get('/:id', controller.show);
router.post('/', controller.create);
router.put('/:id', controller.upsert);
router.patch('/:id', controller.patch);
router.delete('/:id', controller.destroy);
// Custom routes
router.get('/activeexams/:id', controller.getAvailableExams);
router.get('/openexams/get', controller.getOpenExams);
router.get('/instructor/:id', controller.getInstructor);
router.get('/testsites/get', controller.getTestSites);
router.get('/courses/get', controller.getCourseList);
router.get('/timerestrictions/:id/:uid/:uuid', controller.getTimeRestrictions);
router.get('/fulldays/:id/:uid', controller.getFullDays);
router.get('/getexam/:id/:uid', controller.findExam); // DOESNT WORK
router.post('/saveexam/', controller.saveExam);
router.get('/locations', controller.getTestSites);
module.exports = router;
点击端点的服务
'use strict';
const angular = require('angular');
/*@ngInject*/
export function proctoringService($resource) {
return $resource('api/proctorings/:controller/:id/:uid/:uuid', {
id: '@_id'
}, {
getAvailableExams: { method: 'GET', params: { controller: 'activeexams' }, isArray: true },
getOpenExams: { method: 'GET', params: { controller: 'openexams', id: 'get' } },
getCourseList: { method: 'GET', params: { controller: 'courses', id: 'get', }, isArray: true, },
getInstructor: { method: 'GET', params: { controller: 'instructor' } },
getTestSites: { method: 'GET', params: { controller: 'testsites', id: 'get' }, isArray: true },
getFullTimes: { method: 'GET', params: { controller: 'timerestrictions' }, isArray: true },
saveExam: { method: 'POST', params: { controller: 'saveexam' } },
getFullDays: { method: 'GET', params: { controller: 'fulldays' }, isArray: true },
getMyActiveExams: { method: 'GET', params: { controller: 'instructor', id: 'activeexams' }, isArray: true, },
findExam: { method: 'GET', params: { controller: 'getexam' } },
});
}
export default angular.module('proctoringApp.proctoring', [])
.factory('proctoring', proctoringService)
.name;
端点控制器:
'use strict';
import jsonpatch from 'fast-json-patch';
import {Proctoring, Exam, User, Testsite} from '../../sqldb';
function respondWithResult(res, statusCode) {
statusCode = statusCode || 200;
return function(entity) {
if(entity) {
return res.status(statusCode).json(entity);
}
return null;
};
}
function patchUpdates(patches) {
return function(entity) {
try {
// eslint-disable-next-line prefer-reflect
jsonpatch.apply(entity, patches, /*validate*/ true);
} catch(err) {
return Promise.reject(err);
}
return entity.save();
};
}
function removeEntity(res) {
return function(entity) {
if(entity) {
return entity.destroy()
.then(() => {
res.status(204).end();
});
}
};
}
function handleEntityNotFound(res) {
return function(entity) {
if(!entity) {
res.status(404).end();
return null;
}
return entity;
};
}
function handleError(res, statusCode) {
statusCode = statusCode || 500;
return function(err) {
res.status(statusCode).send(err);
};
}
// Gets a list of Proctorings
export function index(req, res) {
return Proctoring.findAll()
.then(respondWithResult(res))
.catch(handleError(res));
}
// Gets a single Proctoring from the DB
export function show(req, res) {
return Proctoring.find({
where: {
_id: req.params.id
}
})
.then(handleEntityNotFound(res))
.then(respondWithResult(res))
.catch(handleError(res));
}
// Creates a new Proctoring in the DB
export function create(req, res) {
return Proctoring.create(req.body)
.then(respondWithResult(res, 201))
.catch(handleError(res));
}
// Upserts the given Proctoring in the DB at the specified ID
export function upsert(req, res) {
if(req.body._id) {
Reflect.deleteProperty(req.body, '_id');
}
return Proctoring.upsert(req.body, {
where: {
_id: req.params.id
}
})
.then(respondWithResult(res))
.catch(handleError(res));
}
// Updates an existing Proctoring in the DB
export function patch(req, res) {
if(req.body._id) {
Reflect.deleteProperty(req.body, '_id');
}
return Proctoring.find({
where: {
_id: req.params.id
}
})
.then(handleEntityNotFound(res))
.then(patchUpdates(req.body))
.then(respondWithResult(res))
.catch(handleError(res));
}
// Deletes a Proctoring from the DB
export function destroy(req, res) {
return Proctoring.find({
where: {
_id: req.params.id
}
})
.then(handleEntityNotFound(res))
.then(removeEntity(res))
.catch(handleError(res));
}
// Creates a new Exam in the DB
export function saveExam(req, res) {
return Exam.create(req.body)
.then(respondWithResult(res, 201))
.catch(handleError(res));
}
export function getAvailableExams(req, res) {
let today = new Date();
today.setDate(today.getDate() + 7);
today = today.toISOString();
// Return tests that start date is less
//than today and end date is greater than today
return Exam.findAll({
where: {
course: req.params.id,
enddate: {
gte: today
}
}
})
.then(respondWithResult(res))
.catch(handleError(res));
}
export function getOpenExams(req, res) {
let today = new Date().toISOString();
return Exam.findAndCountAll({
where: {
startdate: {
lte: today
},
enddate: {
gte: today
}
}
})
.then(respondWithResult(res))
.catch(handleError(res));
}
export function getMyActiveExams(req, res) {
let today = new Date().toISOString();
return Exam.findAll({
where: {
uid: req.params.uid,
startdate: {
lte: today
},
enddate: {
gte: today
}
}
})
.then(respondWithResult(res))
.catch(handleError(res));
}
export function getTestSites(req, res) {
return Testsite.findAll()
.then(respondWithResult(res))
.catch(handleError(res));
}
export function getInstructor(req, res) {
return User.find({
where: {
_id: req.params.id
}
})
.then(handleEntityNotFound(res))
.then(respondWithResult(res))
.catch(handleError(res));
}
export function getCourseList(req, res) {
return Exam.findAll({
attributes: ['course'],
group: 'course'
})
.then(respondWithResult(res))
.catch(handleError(res));
}
export function getFullDays(req, res) {
return Proctoring.findAll({
attributes: ['testdate'],
where: {
lid: req.params.id,
},
group: ['testdate', 'shift'],
having: ['count(*) >= ' + req.params.uid],
})
.then(respondWithResult(res))
.catch(handleError(res));
}
export function getTimeRestrictions(req, res) {
let D = new Date(req.params.uuid).toISOString();
// DONE: Get restricted times for given day selected
return Proctoring.findAll({
attributes: ['shift'],
where: {
lid: req.params.id,
testdate: D
},
group: ['shift'],
having: ['count(*) >=' + req.params.uid],
})
.then(respondWithResult(res))
.catch(handleError(res));
}
export function findExam(req, res) {
return Proctoring.find({
where: {
uid: req.params.id,
eid: req.params.uid,
}
})
.then(handleEntityNotFound(res))
.then(respondWithResult(res))
.catch(handleError(res));
}
当我尝试使用浏览器或邮递员访问我的所有其他端点时,它们会按原样返回。当我尝试添加任何新的简单端点时,找不到它们。
我不知道你可以拥有多少个端点是否存在某种限制;不应该有。
有人有什么想法吗?我收到错误404.