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


TypeScript Response.set方法代碼示例

本文整理匯總了TypeScript中express.Response.set方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Response.set方法的具體用法?TypeScript Response.set怎麽用?TypeScript Response.set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在express.Response的用法示例。


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

示例1: async

    async (req: Request, res: Response): Promise<void> => {
      const templateData: TemplateDataInterface = getTemplateData(page);

      if (!page.content) {
        return renderError(res, templateData);
      }

      // Blog Page render
      if (page.action.startsWith("/blog")) {
        const slug: string = req.params.id;
        const post = page.action !== "/blog"
          ? await getPost(posts, slug)
          : null;

        if (post) {
          if (post.error) {
            return renderError(res, templateData);
          }

          if (post.redirect) {
            return res.status(301)
              .redirect(`https://archive.drublic.de/blog/${post.redirect}`);
          }
        }

        return res.render(page.content, {
          ...templateData,
          ...getPostsData(),
          post,
        });
      }

      if (page.action === "/") {
        const data = {
          ...templateData,
          ...getPostsData(),
          ...getWdPostsData(),
        };

        return res
          .set({
            "Cache-Control": `max-age=${60 * 60 * 24}`,
          })
          .render(page.content, data);
      }

      // Normal page render
      try {
        return res
          .set({
            "Cache-Control": `max-age=${60 * 60 * 24}`,
          })
          .render(page.content, templateData);
      } catch (error) {
        return renderError(res, templateData);
      }
    },
開發者ID:drublic,項目名稱:vc,代碼行數:57,代碼來源:index.ts

示例2: signIn

 signIn(res: Response, user: User): TokenUserDto {
   const token = this.createToken(user);
   res.set('Authorization', token.accessToken);
   res.set('expiresIn', '' + token.expiresIn);
   return {
     id: user.id,
     name: user.name,
     email: user.email,
     role: user.role,
     clubId: user.clubId
   }
 }
開發者ID:OysteinAmundsen,項目名稱:gymsystems,代碼行數:12,代碼來源:auth.service.ts

示例3: setODataVersion

	/**
	 * Sets the OData-Version response header. This must be delivered by an OData-Server
	 * @param res
	 * @private
	 */
	setODataVersion(res:Response, version: string) {
		// default for OData version is 4.0
		if(!version) {
			version = "4.0"
		}
		if(version === "4.0") {
			res.set('OData-Version', version);
		} else if(version === "2.0") {
			res.set('dataserviceversion', version);
		}

	}
開發者ID:draschke,項目名稱:n-odata-server,代碼行數:17,代碼來源:BaseRequestHandler.ts

示例4: function

 return function(req: Request, res: Response): void {
   const cdn = 'https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.13.1'
   res.set('content-type', 'text/html')
   res.send(`
     <html>
     <head>
       <title>${spec.info.title} API Documentation</title>
       <link rel="stylesheet" type="text/css" href="${cdn}/swagger-ui.css">
     </head>
     <body>
       <div id="swagger-ui"></div>
       <script src="${cdn}/swagger-ui-bundle.js"></script>
       <script src="${cdn}/swagger-ui-standalone-preset.js"></script>
       <script>
         window.onload = function () {
           window.ui = SwaggerUIBundle({
             url: new URL("${swaggerPath}", window.location.href).href,
             dom_id: '#swagger-ui',
             deepLinking: true,
             presets: [
               SwaggerUIBundle.presets.apis,
               SwaggerUIStandalonePreset
             ],
             plugins: [
               SwaggerUIBundle.plugins.DownloadUrl
             ],
             layout: "StandaloneLayout"
           })
         }
       </script>
   `)
   res.end()
 }
開發者ID:patrickhulce,項目名稱:klay,代碼行數:33,代碼來源:swagger.ts

示例5: next

 .then(session => {
     // console.log('new session created', session.sessionData);
     let token = JWT.sign({sessionId: session.sessionId});
     res.set('X-Auth-Token', token);
     req.session = session;
     next();
 });
開發者ID:VestaRayanAfzar,項目名稱:express-api-template,代碼行數:7,代碼來源:session.ts

示例6: renderSitemap

  export function renderSitemap(req: Request, res: Response) {
    var cfg: ConfigService = ConfigService.getInstance();
    var rs: RoutingService = RoutingService.getInstance();
    res.set('Content-Type', 'text/xml');
    res.status(200).render('sitemap', {'routes': rs.flatRoutes, 'siteRoot': cfg.siteRoot});

  }
開發者ID:stibi,項目名稱:docs-site,代碼行數:7,代碼來源:SitemapController.ts

示例7: newSession

 .then(session => {
     if (!session) {
         // session has been expired
         return newSession();
     }
     // console.log('session verified', session.sessionData);
     res.set('X-Auth-Token', token);
     req.session = session;
     next();
 });
開發者ID:VestaRayanAfzar,項目名稱:express-api-template,代碼行數:10,代碼來源:session.ts

示例8: catch

app.post("/auth", (req: Request, res: Response, next: NextFunction) => {
    const token = req.body.token;
    try { 
        jwt.verify(token, Key.PUBLIC, {algorithms: ["RS256"]});
    } catch (e) {
        next({message: "@@@@ トークン不正 " + e.message });
        return;
    }
    res.set("Content-Type", "aplication/json; charset=utf-8")
    .json({ message: "@@@@ トークン正常"});
});
開發者ID:tkwasabi,項目名稱:Angular-study,代碼行數:11,代碼來源:www.ts

示例9: function

router.post('/login', function(req: Request, res: Response, next: Function) {
    let username = req.body.username;
    let password = req.body.password;
    let user = UserService.findById(username);
    if(user && (password === user.password)) {
        res.set('jwt', jsonwebtoken.sign({sub: user.id}, 'secret'));
        res.sendStatus(200);
    } else {
        res.sendStatus(403);
    }
});
開發者ID:DaniOtero,項目名稱:jwt-express-demo,代碼行數:11,代碼來源:user.ts

示例10: return

 return (req: Request, res: Response, next: RequestHandler) => {
     res.set('OData-Version', '4.0');
     
     var data = this.document(format)
     if (!data['@odata.context']) {
         var url = req.protocol + '://' + req.get('host') + req.originalUrl.split("?").shift();
         if(url.slice(-1) !== '/') url += '/'
         data['@odata.context'] = url + '$metadata';
     }
     
     res.json(data);
 };
開發者ID:jaystack,項目名稱:odata-v4-service-document,代碼行數:12,代碼來源:serviceDocument.ts

示例11: async

    async (req: Request, res: Response): Promise<void> => {
      const templateData = getTemplateData({
        title: "",
        action: "/",
      });
      const posts: any[] = await getPosts();

      return res
        .set({
          "Content-Type": "application/xml; charset=utf-8",
          "Cache-Control": `max-age=${60 * 60 * 24}`,
        })
        .render("feed", {
          layout: false,
          ...templateData,
          posts,
        });
    },
開發者ID:drublic,項目名稱:vc,代碼行數:18,代碼來源:feed.ts

示例12: postFeed

export function postFeed(req: Request, res: Response) {
   if (!blog.postInfoLoaded) {
      if (rssRetries >= MAX_RSS_RETRIES) {
         log.error(`Unable to load blog after ${MAX_RSS_RETRIES} tries`);
         view.notFound(req, res);
         // reset tries so page can be refreshed
         rssRetries = 0;
      } else {
         rssRetries++;
         log.error(
            `Blog posts not ready when creating RSS feed — attempt ${rssRetries}`
         );
         setTimeout(() => {
            postFeed(req, res);
         }, 1000);
      }
      return;
   }

   res.set(Header.Content.Type, MimeType.XML);
   res.write(render(blog));
   res.end();
}
開發者ID:Trail-Image,項目名稱:blog,代碼行數:23,代碼來源:rss.ts

示例13:

app.use((err: any, req: Request, res: Response, next: NextFunction) => {
    // レスポンス
    res.set("Content-Type", "application/json; charset=utf-8").json(err);
});
開發者ID:tkwasabi,項目名稱:Angular-study,代碼行數:4,代碼來源:www.ts

示例14: next

  app.use(function (req: IRequest, res: Response, next: NextFunction): void {
    res.set(corsHeaders);
  next();
});
開發者ID:dadakoko,項目名稱:play-server,代碼行數:4,代碼來源:app.ts

示例15: function

  app.options('*', function (req: IRequest, res: Response, next: NextFunction): void {
    res.set(corsHeaders).end();
});
開發者ID:dadakoko,項目名稱:play-server,代碼行數:3,代碼來源:app.ts


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