當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。