当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Application.route方法代码示例

本文整理汇总了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);
}
开发者ID:vvscode,项目名称:code-notes,代码行数:8,代码来源:api.ts

示例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);

    });


}
开发者ID:MidoShahin,项目名称:Chat-App-using-ngrx-store,代码行数:35,代码来源:apiGetUserThreads.ts

示例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) => {

        });

}
开发者ID:enrifransch,项目名称:matrix-catcher,代码行数:43,代码来源:apiScan.ts

示例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();

    });

}
开发者ID:MidoShahin,项目名称:Chat-App-using-ngrx-store,代码行数:41,代码来源:apiSaveNewMessage.ts

示例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});

    });

}
开发者ID:MidoShahin,项目名称:Chat-App-using-ngrx-store,代码行数:23,代码来源:apiMessageNotificationsPerUser.ts

示例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);
});
开发者ID:mrplanktonlex,项目名称:angular-ngrx-course,代码行数:31,代码来源:server.ts

示例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);        
    }
开发者ID:mromanjr93,项目名称:nodejsddd,代码行数:46,代码来源:routes.ts

示例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);
开发者ID:bala1074,项目名称:angular-security-course,代码行数:29,代码来源:server.ts

示例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);
});




开发者ID:mrplanktonlex,项目名称:angular-material-course,代码行数:21,代码来源:server.ts


注:本文中的express.Application.route方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。