當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript micro.send函數代碼示例

本文整理匯總了TypeScript中micro.send函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript send函數的具體用法?TypeScript send怎麽用?TypeScript send使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了send函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: async

 async (req: ServerRequest, res: ServerResponse) => {
   try {
     const profile = await getProfile({
       username: decodeURIComponent(req.params.username)
     });
     if (!profile) {
       throw {
         httpStatus: 404,
         message: "Profile Not Found"
       };
     }
     const { plugins, score, timestamp, game, enb, tag } = profile;
     const files = {};
     for (const f of ["plugins", "modlist", "ini", "prefsini"]) {
       files[f] = !profile[f] ? 0 : profile[f].length;
     }
     send(res, 200, {
       plugins,
       score,
       timestamp,
       game,
       enb,
       tag,
       files
     });
   } catch (e) {
     console.log(e);
     send(res, e.httpStatus || 500, e.message || null);
   }
 }
開發者ID:Modwatch,項目名稱:API,代碼行數:30,代碼來源:user.ts

示例2: async

 async (req: ServerRequest, res: ServerResponse) => {
   try {
     const token = await verifyToken(await getToken(req));
     if (
       decodeURIComponent(req.params.username) !== token.sub &&
       !token.scopes.includes("admin")
     ) {
       send(res, 401);
       return;
     }
     const profile = await getProfile({
       username: decodeURIComponent(req.params.username)
     });
     if (!profile) {
       throw {
         httpStatus: 404,
         message: "Profile Not Found"
       };
     }
     if (profile.roles.includes("admin")) {
       send(res, 401);
       return;
     }
     await deleteProfile(
       decodeURIComponent(req.params.username),
       null,
       token
     );
     send(res, 200);
   } catch (e) {
     console.log(e);
     send(res, e.httpStatus || 500, e.message || null);
   }
 }
開發者ID:Modwatch,項目名稱:API,代碼行數:34,代碼來源:oauth.ts

示例3: get

 get("/api/users/count", async (req: ServerRequest, res: ServerResponse) => {
   try {
     send(res, 200, await getUsersCount());
   } catch (e) {
     console.log(e);
     send(res, 500);
   }
 }),
開發者ID:Modwatch,項目名稱:API,代碼行數:8,代碼來源:users.ts

示例4: post

 post("/auth/checkToken", async (req: ServerRequest, res: ServerResponse) => {
   try {
     const body = (await json(req)) as { token: string; username: string };
     await verifyToken(body.token);
     send(res, 200, { token: body.token });
   } catch (e) {
     console.log(e);
     send(res, e.httpStatus || 500, e.message || null);
   }
 }),
開發者ID:Modwatch,項目名稱:API,代碼行數:10,代碼來源:auth.ts

示例5: post

 post("/loadorder", async (req: ServerRequest, res: ServerResponse) => {
   try {
     const body = (await json(req)) as Modwatch.Profile;
     const profile = {
       ...body,
       timestamp: new Date()
     };
     send(res, 201, await uploadProfile(profile, getToken(req)));
   } catch (e) {
     console.log(e);
     send(res, e.httpStatus || 500, e.message || null);
   }
 })
開發者ID:Modwatch,項目名稱:API,代碼行數:13,代碼來源:upload.ts

示例6: get

 get("/oauth/verify", async (req: ServerRequest, res: ServerResponse) => {
   try {
     const token = await verifyToken(await getToken(req));
     if (new Date() > new Date(token.exp)) {
       send(res, 401, "Invalid Token");
       return;
     }
     send(res, 200);
   } catch (e) {
     console.log(e);
     send(res, e.httpStatus || 500, e.message || null);
   }
 }),
開發者ID:Modwatch,項目名稱:API,代碼行數:13,代碼來源:oauth.ts

示例7: async

 async (req: ServerRequest, res: ServerResponse) => {
   const users = await searchProfiles(
     decodeURIComponent(req.params.query),
     req.params.limit ? +req.params.limit : undefined
   );
   send(res, 200, users);
 }
開發者ID:Modwatch,項目名稱:API,代碼行數:7,代碼來源:users.ts


注:本文中的micro.send函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。