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


TypeScript express類代碼示例

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


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

示例1: startServer

import * as express from 'express';
import { Application } from 'express';
import { SeedWebServer } from '../seed/server';


export class ProjectWebServer extends SeedWebServer {
  // Override and modify the server code in this class.

  /**
   * This method is called once regardless of how the server is started, and this
   * is the starting point of the project's custom server code.
   */
  public startServer() {
    super.startServer();

    // Add project server startup code here.
  }
}

let app: Application = express();
let webServer = new ProjectWebServer(app);
export default webServer;
export function serveSPA() { webServer.serveSPA(); }
export function notifyLiveReload(e: any) { webServer.notifyLiveReload(e); }
export function serveDocs() { webServer.serveDocs(); }
export function serveCoverage() { webServer.serveCoverage(); }
export function serveProd() { webServer.serveProd(); }
開發者ID:hellofornow,項目名稱:angular2-seed-advanced,代碼行數:27,代碼來源:server.ts

示例2: describe

describe("Check Pagination with custom keyword for limit and offset", function(){

  let app = express();
  ServiceLoader.loadService(app, new serviceCustomPagination());

  it("should return all the result", function(done){

    var data = DataHelper.getTestData();
    request(app)
    .get("/paginationCustom/666")
    .expect(function(res) {
      let expected = { _links:
        { self: {
          href:"/paginationCustom/666"}
        }, data: data}
        
      assert(res.body._links);
      assert.equal(res.body._links.self.href, expected._links.self.href);
      assert.equal(res.body.data.length, expected.data.length);

      DataHelper.testData(res.body.data, expected.data, 0, 13);

    }).end(done);
  });


  it("should return the four first result", function(done){

    request(app)
    .get("/paginationCustom/666?limite=4")
    .expect(function(res) {
      let expected = { _links:
        { self: {
          href:"/paginationCustom/666?limite=4"}
        }, data: [{firstName:"Peter", lastName:"Parker", secretIdentity: "Spiderman", offset:"0"},
        {firstName:"Bruce", lastName:"Wayne", secretIdentity: "Batman", offset:"1"},
        {firstName:"Clark", lastName:"Kent", secretIdentity: "Superman", offset:"2"},
        {firstName:"Tony", lastName:"Stark", secretIdentity: "Iron Man", offset:"3"}]}

      assert.equal(res.body._links.self.href, expected._links.self.href);
      assert.equal(res.body.data.length, expected.data.length);

      DataHelper.testData(res.body.data, expected.data, 0, 4);

    }).end(done);
  });

  it("should return all the result from offset 8", function(done){

    request(app)
    .get("/paginationCustom/666?offsetIndex=8")
    .expect(function(res) {
      let expected = { _links:
        { self: {
          href:"/paginationCustom/666?offsetIndex=8"}
        }, data: [{firstName:"Matt", lastName:"Murdock", secretIdentity: "Daredevil", offset:"8"},
        {firstName:"Wade", lastName:"Wilson", secretIdentity: "Deadpool", offset:"9"},
        {firstName:"Elektra", lastName:"Natchios", secretIdentity: "Elektra", offset:"10"},
        {firstName:"Dave", lastName:"Lizewski", secretIdentity: "Kick-Ass", offset:"11"},
        {firstName:"Franck", lastName:"Castle", secretIdentity: "Punisher", offset:"12"}]}

      assert.equal(res.body._links.self.href, expected._links.self.href);
      assert.equal(res.body.data.length, expected.data.length);

      DataHelper.testData(res.body.data, expected.data, 8, 5);

    }).end(done);
  });

  it("should return the first three result", function(done){

    request(app)
    .get("/paginationCustom/666?limite=3&index=0")
    .expect(function(res) {
      let expected = { _links:
        { self: {
          href:"/paginationCustom/666?limite=3&index=0"}
        }, data: [{firstName:"Peter", lastName:"Parker", secretIdentity: "Spiderman", offset:"0"},
        {firstName:"Bruce", lastName:"Wayne", secretIdentity: "Batman", offset:"1"},
        {firstName:"Clark", lastName:"Kent", secretIdentity: "Superman", offset:"2"}]}
      assert.equal(res.body._links.self.href, expected._links.self.href);
      assert.equal(res.body.data.length, expected.data.length);

      DataHelper.testData(res.body.data, expected.data, 0, 3);

    }).end(done);
  });

  it("should return the two result start with offset 5", function(done){

    request(app)
    .get("/paginationCustom/666?limite=2&index=5")
    .expect(function(res) {
      console.log(res.body);
      let expected = { _links:
        { self: {
          href:"/paginationCustom/666?limite=2&index=5"}
        }, data: [{firstName:"Bruce", lastName:"Banner", secretIdentity: "Hulk", offset:"5"},
                {firstName:"Natasha", lastName:"Romanoff", secretIdentity: "Black Widow", offset:"6"}]}

//.........這裏部分代碼省略.........
開發者ID:lynchmaniac,項目名稱:threerest,代碼行數:101,代碼來源:test-custom-pagination.ts

示例3: Sequelize

import * as epilogue from 'epilogue';
import * as express from 'express';
import * as Sequelize from 'sequelize';

const database = new Sequelize({ });

epilogue.initialize({
    app: express(),
    sequelize: database
});

epilogue.initialize({
    app: express(),
    sequelize: database,
    base: ''
});

epilogue.initialize({
    app: express(),
    sequelize: database,
    base: '',
    updateMethod: ''
});

const User = database.define('User', {
    username: Sequelize.STRING,
    birthday: Sequelize.DATE
});

epilogue.resource({
    model: User,
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:epilogue-tests.ts

示例4: express

import * as express from "express";
import * as sassMiddleware from "node-sass-middleware";
import * as path from "path";
var app = express();
app.use(sassMiddleware({
    /* Options */
    src: __dirname,
    dest: path.join(__dirname, 'public'),
    debug: true,
    outputStyle: 'compressed',
    prefix:  '/prefix'  // Where prefix is at <link rel="stylesheets" href="prefix/style.css"/>
}));
app.use(express.static(path.join(__dirname, 'public')));
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:13,代碼來源:node-sass-middleware-tests.ts

示例5: enableProdMode

import 'zone.js/dist/zone-node';
import 'reflect-metadata';
import { enableProdMode } from '@angular/core';
import { ngExpressEngine } from '@nguniversal/express-engine';
import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader';

import * as express from 'express';
import * as bodyParser from 'body-parser';
import * as cors from 'cors';
import * as compression from 'compression';

import { join } from 'path';

enableProdMode();

export const app = express();

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

// const DIST_FOLDER = join(process.cwd(), 'dist');

const {AppServerModuleNgFactory, LAZY_MODULE_MAP} = require('./dist/server/main');

app.engine('html', ngExpressEngine({
  bootstrap: AppServerModuleNgFactory,
  providers: [
    provideModuleMap(LAZY_MODULE_MAP)
  ]
開發者ID:nnoumegni,項目名稱:jetcamer,代碼行數:31,代碼來源:server.ts

示例6: constructor

 constructor(private expressContactRouter: ExpressContactRouter) {
   // create expressjs application
   this.expressApplication = express();
 }
開發者ID:rajajhansi,項目名稱:aspnetcore-aurelia-tutorial,代碼行數:4,代碼來源:express-application.ts

示例7: Express

/**
 * Created by chapeau on 7/25/16.
 */
///<reference path="../typings/index.d.ts"/>

import * as Express from 'express';
var app = Express();

app.set('view-engine', 'ejs');

app.get('/',(req, res)=>{
    res.render('../client/views/index.ejs');
});

app.use('/static', Express.static('public'));

app.listen(8081, function(){
    console.log('App listening!');
});
開發者ID:FChapeau,項目名稱:Hokage,代碼行數:19,代碼來源:server.ts

示例8: express

// Imports
	import * as express from 'express';
	import * as path from 'path';
	import {config} from '../../config.ts';

// Server setup
	let serverConfig = config.servers.statics;
	export let server = express();

// Setup statics
	let filesPath = path.join(process.cwd(), 'src/setup/statics/files');
	server.use(config.httpRoutes.statics.path, express.static(filesPath));

// Start function
	export function startServer () {
		server.listen(serverConfig.port, function () {
			console.log('Serving statics at '+serverConfig.domain+':'+serverConfig.port);
		});
	}
開發者ID:dsilva2401,項目名稱:server-seed,代碼行數:19,代碼來源:server.ts

示例9: async

export const bootstrapApp = async (): Promise<BootstrapSettings> => {
    /**
     * We create a new express server instance.
     */
    const app: express.Application = express();

    app.use(json({ limit: "50mb" }));
    app.use(urlencoded({ extended: true }));

    useExpressServer(app, {
        cors: true,
        routePrefix: env.app.routePrefix,
        defaultErrorHandler: false,
        classTransformer: true,
        validation: true,
        /**
         * We can add options about how routing-controllers should configure itself.
         * Here we specify what controllers should be registered in our express server.
         */
        controllers: env.app.dirs.controllers,
        middlewares: env.app.dirs.middlewares,
    });

    winston.configure({
        transports: [
            new winston.transports.Console({
                level: env.log.level,
                handleExceptions: true,
                json: env.log.json,
                timestamp: env.node !== "development",
                colorize: env.node === "development",
            }),
        ],
    });

    routingUseContainer(Container);
    ormUseContainer(Container);
    classValidatorUseContainer(Container);

    // Register validator schemes
    env.app.dirs.validatorSchemes.forEach((pattern) => {
        glob(pattern, (err: any, files: Array<string>) => {
            for (const file of files) {
                const schemas = require(file);

                Object.keys(schemas).forEach((key) => {
                    registerSchema(schemas[key]);
                });
            }
        });
    });
    env.app.dirs.subscribers.forEach((pattern) => {
        glob(pattern, (err: any, files: Array<string>) => {
            for (const file of files) {
                require(file);
            }
        });
    });

    const initTypeORM = async () => {
        const loadedConnectionOptions = await getConnectionOptions();

        const connectionOptions = Object.assign(loadedConnectionOptions, {
            type: env.db.type as any, // See createConnection options for valid types
            host: env.db.host,
            port: env.db.port,
            username: env.db.username,
            password: env.db.password,
            database: env.db.database,
            synchronize: env.db.synchronize,
            logging: env.db.logging,
            entities: env.app.dirs.entities,
            migrations: env.app.dirs.migrations,
        });

        return createConnection(connectionOptions);
    };

    app.get(
        env.app.routePrefix,
        (req: express.Request, res: express.Response) => {
            return res.json({
                name: env.app.name,
                version: env.app.version,
                description: env.app.description,
            });
        },
    );

    const log = new Logger(__filename);

    try {
        const connection = await initTypeORM();

        const server: http.Server = app.listen(env.app.port);

        banner(log);

        return {
            app,
//.........這裏部分代碼省略.........
開發者ID:LogansUA,項目名稱:jest-import-error,代碼行數:101,代碼來源:bootstrap.ts

示例10: it

      it("returns a resolved promise", () => {
        const setupProxyServer = (provider as any).setupProxyServer
        const app = express()

        expect(setupProxyServer(app)).to.be.an.instanceOf(http.Server)
      })
開發者ID:pact-foundation,項目名稱:pact-js,代碼行數:6,代碼來源:messageProviderPact.spec.ts


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