本文整理汇总了TypeScript中express.Application类的典型用法代码示例。如果您正苦于以下问题:TypeScript Application类的具体用法?TypeScript Application怎么用?TypeScript Application使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Application类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
export var setupVerbRoutes = function (baseUrl: string, expressApp: Application) {
var verbHandler: VerbHandler = new VerbHandler();
var verbController: VerbController = new VerbController(verbHandler);
expressApp.get(baseUrl + "verb/get", async (req, res) => {
verbController.getAll(req, res);
});
expressApp.get(baseUrl + "verb/get/:id", async (req, res) => {
verbController.getOne(req, res);
});
expressApp.post(baseUrl + "verb/create", isAuthenticatedApiMiddleware, async (req, res) => {
verbController.create(req, res);
});
expressApp.post(baseUrl + "verb/update", isAuthenticatedApiMiddleware, async (req, res) => {
verbController.update(req, res);
});
expressApp.post(baseUrl + "verb/remove", isAuthenticatedApiMiddleware, async (req, res) => {
verbController.remove(req, res);
});
}
示例2: MakeRoutes
public static MakeRoutes(express: Application): void {
const keys = Object.keys(routes);
Server.Log('Registering routes: ', keys);
for (let key in keys) {
key = keys[key];
if (!routes.hasOwnProperty(key)) {
continue;
}
let route = routes[key];
let split = key.split(' ');
if (split[0] === 'post') {
express.post(split[1], route);
} else {
express.get(split.length === 1 ? split[0] : split[1], route);
}
}
express.use(function(req: Request, res: Response) {
res.status(404).render('errors/404.html', { title: '404: File Not Found' });
});
express.use(function(error: Error, req: Request, res: Response, next: any) {
res.status(500).render('errors/500.html', { title: '500: Internal Server Error', error: error });
});
}
示例3: 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);
}
示例4: applyLimitsToApp
/**
* Applies limits config to app
*/
export default function applyLimitsToApp(app: Application, config: AppConfig) {
if (config.trustProxy) {
app.enable('trust proxy');
}
app.use('/api/', new RateLimit(applyLimits(config.api.options.limits)));
app.use('/peer/', new RateLimit(applyLimits(config.peers.options.limits)));
}
示例5: function
export default function(app: Application, apiRoot: string) {
var id = "/:id(\\d+)";
app.get(apiRoot, send(req => Product.findAll()));
app.get(apiRoot + id, send(req => Product.find(+req.params.id)));
app.post(apiRoot, send(req => {
var data = req.body;
delete data.id;
return Product.create(data);
}));
app.put(apiRoot + id, send(req => Product.update(req.body, { where: { id: +req.params.id } }), 200));
app.delete(apiRoot + id, send(req => Product.destroy({ where: { id: +req.params.id } }), 204));
}
示例6: default
export default (app: Application, config: Config) => {
app.use(buster());
let staticOptions = {};
if (process.env.NODE_ENV === 'production') {
staticOptions = { maxAge: '30d' };
}
app.use(express.static(
path.join(__dirname, '..', '..', '..', 'public'),
staticOptions));
app.use(cookies(config));
app.use(session());
};
示例7: constructor
constructor(public app: Application, public router: Router) {
new AuthRoutes(app);
new CategoryRoutes(router);
new GameRoutes(router);
const unprotected = ['/api/alive', '/api/games-create', '/api/games-join'];
app.use('/api/', expressJwt({ secret }).unless({ path: unprotected }), router);
app.get('/report/', (req, res) => {
r.table('players').count().then(count => {
res.json(count);
})
});
}
示例8: model
config.collections.forEach((schema: ISchema) => {
const modelSchema = model(schema);
app.get(`/${schema.name}`, async (_req: IRequest, res: Response) =>
res.status(200).json(await modelSchema.find()),
);
app.get(`/${schema.name}/:id`, async (req: IRequest, res: Response) => {
try {
res.status(200).json(await modelSchema.findOne({_id: req.params.id}));
} catch (err) {
res.status(404).json({error: "Not Found"});
}
});
app.post(`/${schema.name}`, async (req: IRequest, res: Response) => {
try {
const newModel = new modelSchema(req.body);
await newModel.save();
res.status(201).json(newModel);
} catch (err) {
res.status(400).json({error: err.message});
}
});
/*
app.put(`/${schema.name}/:id`, async (req: IRequest, res: Response) => {
//
});
app.patch(`/${schema.name}/:id`, async (req: IRequest, res: Response) => {
//
});
app.delete(`/${schema.name}/:id`, (req: IRequest, res: Response) => {
//
});
*/
});
示例9: middleware
middleware(): void {
this.express.use(morgan('dev'));
this.express.use(bodyParser.urlencoded({ extended: true }));
this.express.use(bodyParser.json());
this.express.use(Handlers.errorHandlerApi);
this.express.use(Auth.config().initialize());
this.router(this.express, Auth);
}
示例10: constructor
constructor() {
this.App = new express();
this.App.get('/user/:id', UserRoute.getUser);
this.App.put('/user', MyServer.handleRequest(UserRoute.updateUser));
this.App.listen(3000, () => {
console.log('server started on port 3000');
});
}