خرید بک لینک

Vote count: 0

I want to migrate my routing logic from plain javascript to typescript. In javascript I would use below logic. How can I achieve the same the below in typescript to implement a route by implementing the IRoute interface.The idea is to use a class which handles routing.

route.ts:

var express = require('express');
var myRouter = express.Router();
myRouter.route('/')
.all(function(req,res,next) {
 res.writeHead(200, { 'Content-Type': 'text/plain' });
 next();
})

.get(function(req,res,next){
    res.end('Will send all the promotions to you!');
})

.post(function(req, res, next){
res.end('Will add the promotions: ' + req.body.name + ' with details: ' +  
    req.body.description);    
})

.delete(function(req, res, next){
    res.end('Deleting all promotions');
});
module.exports = myRouter;

app.ts

app.use('/myRoutes',myRouter)

I have tried the solution given - Express.js routes with Typescript but that is not working...

asked 14 secs ago

برچسب: نویسنده: استخدام کار تاريخ: سه شنبه 12 مرداد 1395 ساعت: 22:20

صفحه بندی