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


TypeScript microrouter.post函数代码示例

本文整理汇总了TypeScript中microrouter.post函数的典型用法代码示例。如果您正苦于以下问题:TypeScript post函数的具体用法?TypeScript post怎么用?TypeScript post使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了post函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: createApp

function createApp(options: CreateAppOptions) {
  const graphqlOptions = (options && options.graphqlOptions) || { schema };
  const graphiqlOptions = (options && options.graphiqlOptions) || {
    endpointURL: '/graphql',
  };

  const graphqlHandler = microGraphql(graphqlOptions);
  const graphiqlHandler = microGraphiql(graphiqlOptions);

  return micro(
    router(
      get('/graphql', graphqlHandler),
      post('/graphql', graphqlHandler),
      put('/graphql', graphqlHandler),
      patch('/graphql', graphqlHandler),
      del('/graphql', graphqlHandler),
      head('/graphql', graphqlHandler),
      opts('/graphql', graphqlHandler),

      get('/graphiql', graphiqlHandler),
      post('/graphiql', graphiqlHandler),
      put('/graphiql', graphiqlHandler),
      patch('/graphiql', graphiqlHandler),
      del('/graphiql', graphiqlHandler),
      head('/graphiql', graphiqlHandler),
      opts('/graphiql', graphiqlHandler),

      (req, res) => send(res, 404, 'not found'),
    ),
  );
}
开发者ID:chentsulin,项目名称:apollo-server,代码行数:31,代码来源:microApollo.test.ts

示例2: catch

       });
     } catch (e) {
       console.log(e);
       send(res, e.httpStatus || 500, e.message || null);
     }
   }
 ),
 post(
   //@ts-ignore UrlPattern is allowed as a parameter to micro-router methods
   new UrlPattern("/api/user/:username/delete", usernameRegex),
   async (req: ServerRequest, res: ServerResponse) => {
     try {
       const body = (await json(req)) as { password: string };
       await deleteProfile(
         decodeURIComponent(req.params.username),
         body.password,
         await getToken(req)
       );
       send(res, 200);
     } catch (e) {
       console.log(e);
       send(res, e.httpStatus || 500, e.message || null);
     }
   }
 ),
 post(
   //@ts-ignore UrlPattern is allowed as a parameter to micro-router methods
   new UrlPattern("/api/user/:username/changepass", usernameRegex),
   async (req: ServerRequest, res: ServerResponse) => {
     try {
       const body = (await json(req)) as {
         password: string;
开发者ID:Modwatch,项目名称:API,代码行数:32,代码来源:user.ts

示例3: post

import { post, ServerRequest, ServerResponse } from "microrouter";
import { send, json } from "micro";

import { uploadProfile } from "../database";
import { getToken } from "../utils";

export const routes = [
  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,代码行数:21,代码来源:upload.ts

示例4: post

import { post, ServerRequest, ServerResponse } from "microrouter";
import { send, json } from "micro";

import { getProfile } from "../database";
import { verifyToken, validPassword, generateToken } from "../utils";

export const routes = [
  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);
    }
  }),
  post("/auth/signin", async (req: ServerRequest, res: ServerResponse) => {
    try {
      const body = (await json(req)) as { username: string; password: string };
      const profile = await getProfile({ username: body.username });
      await validPassword(body.password, profile.password);
      const token = await generateToken(body.username, body.password);
      send(res, 200, { token });
    } catch (e) {
      console.log(e);
      send(res, e.httpStatus || 500, e.message || null);
    }
  })
];
开发者ID:Modwatch,项目名称:API,代码行数:30,代码来源:auth.ts

示例5: post

 post("/oauth/authorize", async (req: ServerRequest, res: ServerResponse) => {
   const query = serialize(req.query);
   try {
     const body = (await parse(req)) as Modwatch.Profile;
     const scopes = body.scopes || [];
     if (clients.every(c => req.query.redirect_uri.indexOf(c) !== 0)) {
       res.statusCode = 301;
       res.setHeader(
         "Location",
         `/oauth/authorize?${query}&failed=${encodeURIComponent(
           "Login must be initiated from a valid client"
         )}`
       );
       res.end();
       return;
     }
     if (["username", "password"].filter(q => !!body[q]).length !== 2) {
       res.statusCode = 301;
       res.setHeader(
         "Location",
         `/oauth/authorize?${query}&failed=${encodeURIComponent(
           "Username/Password/Scope Required"
         )}`
       );
       res.end();
       return;
     }
     const profile = await getProfile({ username: body.username });
     if (!profile) {
       throw {
         httpStatus: 404,
         message: "Profile Not Found"
       };
     }
     const roles = profile.roles ? [].concat(profile.roles).sort() : [];
     if (
       !(await validPassword(body.password, profile.password)) ||
       ![]
         .concat(scopes)
         .sort()
         .every((scope, index) => scope === roles[index])
     ) {
       res.statusCode = 301;
       res.setHeader(
         "Location",
         `/oauth/authorize?${query}&failed=${encodeURIComponent(
           "Invalid Credentials"
         )}`
       );
       res.end();
       return;
     }
     const iat = new Date().getTime();
     const token = {
       iss: req.query.redirect_uri,
       aud: "https://api.modwat.ch/",
       sub: profile.username,
       iat,
       exp: iat + 3600 * 1000,
       scopes: [...new Set(["user"].concat(scopes).concat(roles))]
     };
     res.statusCode = 301;
     res.setHeader(
       "Location",
       `${decodeURIComponent(
         req.query.redirect_uri
       )}oauth/access_token/${encodeURIComponent(
         encode(token, process.env.JWTSECRET)
       )}/token_type/Bearer/expires_in/3600`
     );
     res.end();
   } catch (e) {
     console.log(e);
     res.statusCode = 301;
     res.setHeader(
       "Location",
       `/oauth/authorize?${query}&failed=${encodeURIComponent(
         "Invalid Credentials"
       )}`
     );
     res.end();
   }
 }),
开发者ID:Modwatch,项目名称:API,代码行数:83,代码来源:oauth.ts


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