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


TypeScript Application.set方法代码示例

本文整理汇总了TypeScript中express.Application.set方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Application.set方法的具体用法?TypeScript Application.set怎么用?TypeScript Application.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在express.Application的用法示例。


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

示例1: elasticsearchInit

export function elasticsearchInit(app: Application) {
  app.set("elasticsearchClient", client);

  client.indices
    .exists({ index })
    .then(indexExists => {
      if (indexExists) {
        return client.indices.delete({ index });
      }
    })
    .then(() => client.indices.create({ index }))
    .then(() =>
      User.findAll().then(users => {
        users.map(user => user.dataValues).forEach(user => {
          client.index({
            index,
            type: "user",
            id: user.id,
            body: {
              first_name: user.first_name,
              last_name: user.last_name,
              location: user.location
            }
          });
        });
      })
    );
}
开发者ID:jord-goldberg,项目名称:api_take_home,代码行数:28,代码来源:elasticsearch.ts

示例2: configure

 private configure(): void {
     this.app.set("port", this.normalizePort(process.env.PORT || "3000"));
     Currencies.updateCurrencyRate();
     process.on("exit", (code) => {
         clearTimeout(this.timer);
         process.exit(code);
     }).on("SIGABRT", () => {
         clearTimeout(this.timer);
         process.exit(0);
     }).on("SIGINT", () => {
         clearTimeout(this.timer);
         process.exit(0);
     });
     this.timer = Currencies.runRequestLoop(config.get("CURRENCY_UPDATE_TIMEOUT"));
 }
开发者ID:ZulusK,项目名称:Budgetarium,代码行数:15,代码来源:App.ts

示例3: init

export default async function init(app: Application) {
  const sequelize = new Sequelize({
    database: "signafire",
    dialect: "sqlite",
    storage: "./users.sqlite",
    username: "root",
    password: "",
    logging: false,
    modelPaths: [__dirname + "/models"],
    operatorsAliases,
    define: {
      freezeTableName: true
    }
  });

  app.set("sequelizeClient", sequelize);

  const readUserData: () => Promise<any[]> = () =>
    new Promise((resolve, reject) => {
      fs.readFile("./data.json", "utf8", (err, data) => {
        if (err) return reject(err);
        resolve(JSON.parse(data));
      });
    });

  // Sync to the database && populate data
  // Return app afterwards to chain with elasticsearch init
  return sequelize
    .sync({ force: NODE_ENV !== "production" })
    .then(readUserData)
    .then(users => Promise.all(users.map(user => User.create(user))))
    .then(users => {
      console.log(users);
      return app;
    });
}
开发者ID:jord-goldberg,项目名称:api_take_home,代码行数:36,代码来源:sequelize.ts

示例4: connect

import * as express from "express";
import { Application, Request, Response } from "express";
import { OK } from "http-status-codes";
import * as scaffoldRouter from "express-mongoose-scaffold";
import { connect } from "mongoose";
import { render as formRenderer } from "cms-forms";
import { render as gridRenderer } from "cms-grids";
import * as path from "path";
import { model as FoodsModel } from "./models/something";
import { model as CategoriesModel } from "./models/category";

connect(process.env.MONGO_URL || "mongodb://localhost/auto-router-demo");

let app :Application = express();

app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

app.get('/', (request : Request, response : Response) => {
    response.status(OK).send("Hello World");
});

app.use('/admin/categories', scaffoldRouter(CategoriesModel).adminRouter);
app.use('/admin/foods', scaffoldRouter(FoodsModel).adminRouter);
app.use('/api/foods', scaffoldRouter(FoodsModel).apiRouter);

app.use(formRenderer);
app.use(gridRenderer);

app.use((req, res, next) => {
    if (res.html) {
开发者ID:rajivnarayana,项目名称:express-mongoose-scaffold,代码行数:31,代码来源:app.ts

示例5: default

/**
 * Sets up the EJS templating engine.
 */
export default (app: Application) => {
    app.set('views', path.join(__dirname, '..', '..', 'views'));
    app.set('view engine', 'ejs');
};
开发者ID:rla,项目名称:feeds,代码行数:7,代码来源:setupEJS.ts

示例6: express

import * as mongoose from 'mongoose';

import {IRequest} from './interfaces';
import {router as authenticateRoutes} from './routes/authenticate';
import {router as usersRoutes} from './routes/users';
import {router as videosRoutes} from './routes/videos';
import {dbName, dbHost} from "./config";

namespace Play {
  'use strict';

  export const app: Application = express();

// view engine setup
// app.set('views', path.join(__dirname, 'views'));
  app.set('view engine', 'jade');

// uncomment after placing your favicon in /public
// app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
  app.use(logger('dev'));
// use bodyParser middleware to decode json parameters
  app.use(bodyParser.json());
  app.use(bodyParser.json({type: 'application/vnd.api+json'}));
// use bodyParser middleware to decode urlencoded parameters
  app.use(bodyParser.urlencoded({extended: false}));
  app.use(ExpressValidator());
// use cookieParser to extract cookie information from request
  app.use(cookieParser());
  app.use(express.static(path.join(__dirname, 'public')));

  const corsHeaders: Object = {
开发者ID:dadakoko,项目名称:play-server,代码行数:31,代码来源:app.ts

示例7: async

export default async (app: Application) => {
  if (config.database) {
    mongoose.connect(
      config.database.params.connection_string,
      {
        useNewUrlParser: true,
      },
    );
  }

  app.use(bodyParser.urlencoded({ extended: true }));
  app.use(bodyParser.json());

  if (config.sessions) {
    app.use(clientSessions(config.sessions));
  }

  if (config.templates) {
    app.engine(config.templates.type, (await import(config.templates.type)).default.__express);
    app.set("view engine", config.templates.type);
  }

  if (config.pages) {
    config.pages.forEach((pageConfig: IPage) => {
      app.get(pageConfig.route, (_req: IRequest, res: Response) => {
        // req.headers
        if (pageConfig.template) {
          res.render(pageConfig.template, pageConfig.parameters);
        } else {
          res.status(200).json(pageConfig.parameters);
        }
      });
    });
  }

  if (config.static) {
    app.use(expressStatic(`__dirname${config.static}`));
  }

  if (config.collections) {
    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) => {
        //
      });
      */
    });
  }

  /*if (config.auth) {
    config.auth.forEach((authConfig: IAuthConfig) => {
      //
    });
  }*/
};
开发者ID:dandart,项目名称:arsebeatfish,代码行数:81,代码来源:index.ts


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