本文整理匯總了TypeScript中express.Application.route方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Application.route方法的具體用法?TypeScript Application.route怎麽用?TypeScript Application.route使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類express.Application
的用法示例。
在下文中一共展示了Application.route方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: initRestAPI
export function initRestAPI(app: Application) {
app.route("/api/courses").get(getCourses);
app.route("/api/courses/:id").get(getCourseDetail);
app.route("/api/lesson").post(postLesson);
app.route("/api/lesson/:id").patch(patchLesson);
app.route("/api/lesson/:id").delete(deleteLesson);
}
示例2: apiGetUserThreads
export function apiGetUserThreads(app:Application) {
app.route('/api/threads').get((req: Request, res: Response) => {
const participantId = parseInt(req.headers['userid']);
const threadsPerUser = findDbThreadsPerUser(participantId);
let messages: Message[] = [],
participantIds: string[] = [];
threadsPerUser.forEach(thread => {
const threadMessages: Message[] = _.filter(dbMessages, (message:any) => message.threadId == thread.id);
messages = messages.concat(threadMessages);
participantIds = participantIds.concat(_.keys(thread.participants));
});
const participants = _.uniq(participantIds.map(participantId => dbParticipants[participantId]));
const response: AllUserData = {
participants,
messages,
threads: threadsPerUser
};
res.status(200).json(response);
});
}
示例3: apiScan
export function apiScan(app: Application) {
app.route('/scans')
// POST /scans
.post((req: Request, res: Response) => {
const scan = new Scan({
dateTime: new Date(),
latitude: req.body.latitude,
longitude: req.body.longitude,
mission: req.body.mission,
scanFilters: req.body.scanFilters,
notes: req.body.notes
});
scan.save().then((result) => {
console.log('Saving scan registry:\n', JSON.stringify(result, undefined, 2));
res.send(result);
}, (dbError) => {
console.log('Error saving new scan registry:\n', JSON.stringify(dbError, undefined, 2));
res.status(400).send(dbError);
});
})
// GET /scans
.get((req: Request, res: Response) => {
Scan.find().then((scans) => {
res.send(
scans
);
}, (dbError) => {
res.status(400).send(dbError);
});
});
app.route('/scans/:id')
// GET /scans/:id
.get((req: Request, res: Response) => {
})
// DELETE /scan/:id
.delete((req: Request, res: Response) => {
});
}
示例4: apiSaveNewMessage
export function apiSaveNewMessage(app: Application) {
app.route('/api/threads/:id').post((req, res) => {
const payload = req.body;
const threadId = parseInt(req.params.id),
participantId = parseInt(req.headers['userid']);
const message: Message = {
id: messageIdCounter++,
threadId,
timestamp: new Date().getTime(),
text: payload.text,
participantId
};
// save the new message, it's
// already linked to a thread
dbMessages[message.id] = message;
const thread = findThreadById(threadId);
thread.messageIds.push(message.id);
const otherParticipantIds = _.keys(thread.participants).filter(id => parseInt(id) !== participantId);
otherParticipantIds.forEach(participantId => {
thread.participants[participantId] += 1;
dbMessagesQueuePerUser[participantId].push(message.id);
});
thread.participants[participantId] = 0;
res.status(200).send();
});
}
示例5: apiMessageNotificationsPerUser
export function apiMessageNotificationsPerUser(app: Application) {
app.route('/api/notifications/messages').post((req, res) => {
const participantId = req.headers['userid'];
if (!participantId) {
res.status(200).json({payload:[]});
return;
}
const unreadMessageIds = dbMessagesQueuePerUser[participantId];
const unreadMessages = unreadMessageIds.map( messageId => dbMessages[messageId] );
dbMessagesQueuePerUser[participantId] = [];
res.status(200).json({payload: unreadMessages});
});
}
示例6: require
import {getAllCourses, getCourseById} from "./get-courses.route";
import {searchLessons} from "./search-lessons.route";
import {loginUser} from "./auth.route";
import {saveCourse} from "./save-course.route";
const bodyParser = require('body-parser');
const app: Application = express();
app.use(bodyParser.json());
app.route('/api/login').post(loginUser);
app.route('/api/courses').get(getAllCourses);
app.route('/api/courses/:id').put(saveCourse);
app.route('/api/courses/:id').get(getCourseById);
app.route('/api/lessons').get(searchLessons);
const httpServer = app.listen(9000, () => {
console.log("HTTP REST API Server running at http://localhost:" + httpServer.address().port);
});
示例7: initRoutes
initRoutes(app: Application, auth: any): void {
app.route('/api/users').all(auth.config().authenticate()).get(UserRoutes.index);
app.route('/api/users/:id').all(auth.config().authenticate()).get(UserRoutes.findOne);
app.route('/api/users').all(auth.config().authenticate()).post(UserRoutes.create);
app.route('/api/users/:id').all(auth.config().authenticate()).put(UserRoutes.update);
app.route('/api/users/:id').all(auth.config().authenticate()).delete(UserRoutes.destroy);
app.route('/token').post(TokenRoutes.auth);
app.route('/api/outlets').get(OutletRoutes.index);
app.route('/api/outlets/:id').get(OutletRoutes.findOne);
app.route('/api/outlets').post(OutletRoutes.insert);
app.route('/api/outlets/:id').put(OutletRoutes.update);
app.route('/api/outlets/:id').delete(OutletRoutes.destroy);
app.route('/api/outlettypes').get(OutletTypeRoutes.index);
app.route('/api/outlettypes/:id').get(OutletTypeRoutes.findOne);
app.route('/api/outlettypes').post(OutletTypeRoutes.insert);
app.route('/api/outlettypes/:id').put(OutletTypeRoutes.update);
app.route('/api/outlettypes/:id').delete(OutletTypeRoutes.destroy);
app.route('/api/outletmatches').get(OutletMatchRoutes.index);
app.route('/api/outletmatches/:id').get(OutletMatchRoutes.findOne);
app.route('/api/outletmatches').post(OutletMatchRoutes.insert);
app.route('/api/outletmatches/:id').put(OutletMatchRoutes.update);
app.route('/api/outletmatches/:id').delete(OutletMatchRoutes.destroy);
app.route('/api/sections').get(SectionRoutes.index);
app.route('/api/sections/:id').get(SectionRoutes.findOne);
app.route('/api/sections').post(SectionRoutes.insert);
app.route('/api/sections/:id').put(SectionRoutes.update);
app.route('/api/sections/:id').delete(SectionRoutes.destroy);
app.route('/api/sectionmatches').get(SectionMatchRoutes.index);
app.route('/api/sectionmatches/:id').get(SectionMatchRoutes.findOne);
app.route('/api/sectionmatches').post(SectionMatchRoutes.insert);
app.route('/api/sectionmatches/:id').put(SectionMatchRoutes.update);
app.route('/api/sectionmatches/:id').delete(SectionMatchRoutes.destroy);
app.route('/api/providers').get(ProviderRoutes.index);
app.route('/api/providers/:id').get(ProviderRoutes.findOne);
app.route('/api/providers').post(ProviderRoutes.insert);
app.route('/api/providers/:id').put(ProviderRoutes.update);
app.route('/api/providers/:id').delete(ProviderRoutes.destroy);
app.route('/api/dispatcher/:id').post(DispatcherRoutes.toConversorQueue);
}
示例8: require
app.use(cookieParser());
app.use(retrieveUserIdFromRequest);
app.use(bodyParser.json());
const commandLineArgs = require('command-line-args');
const optionDefinitions = [
{ name: 'secure', type: Boolean, defaultOption: true },
];
const options = commandLineArgs(optionDefinitions);
// REST API
app.route('/api/lessons')
.get(checkIfAuthenticated,
_.partial(checkIfAuthorized,['STUDENT']),
readAllLessons);
app.route('/api/admin')
.post(checkIfAuthenticated,
_.partial(checkIfAuthorized,['ADMIN']),
loginAsUser);
app.route('/api/signup')
.post(createUser);
app.route('/api/user')
.get(getUser);
示例9: express
import * as express from 'express';
import {Application} from "express";
import {getAllCourses, getCourseById} from "./get-courses.route";
import {searchLessons} from "./search-lessons.route";
const app: Application = express();
app.route('/api/courses').get(getAllCourses);
app.route('/api/courses/:id').get(getCourseById);
app.route('/api/lessons').get(searchLessons);
const httpServer = app.listen(9000, () => {
console.log("HTTP REST API Server running at http://localhost:" + httpServer.address().port);
});