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


TypeScript method-override.default方法代码示例

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


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

示例1: function

export default function(app) {
  let env = app.get('env');

  app.set('views', config.root + '/server/views');
  app.set('view engine', 'jade');
  app.use(compression());
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(bodyParser.json());
  app.use(methodOverride());
  app.use(cookieParser());
  app.use(passport.initialize());

  app.set('appPath', path.join(config.root, 'client'));

  if ('production' === env) {
    app.use(favicon(path.join(config.root, 'client', 'favicon.ico')));
    app.use(express.static(app.get('appPath')));
    app.use(morgan('dev'));
  }

  if ('development' === env) {
    app.use(require('connect-livereload')());
  }

  if ('development' === env || 'test' === env) {
    app.use(express.static(path.join(config.root, '.tmp')));
    app.use(express.static(app.get('appPath')));
    app.use(morgan('dev'));
    app.use(errorHandler()); // Error handler - has to be last
  }
}
开发者ID:Jeremy-Doucet,项目名称:Blog-Example-Typescript,代码行数:31,代码来源:express.ts

示例2:

const init = (app) => {
  app.set("port", (process.env.PORT || 3000));

  // X-Powered-By header has no functional value.
  // Keeping it makes it easier for an attacker to build the site"s profile
  // It can be removed safely
  app.disable("x-powered-by");
  app.set("views", path.join(__dirname, "..", "views"));

  app.set("view cache", false);

  app.use(cookieParser());
  // app.use(auth({ loginUrl: "/", ignorePatterns: ["^/assets/", "^/api/"] }));
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
  app.use(methodOverride());
  app.use(express.static(path.join(__dirname, "../..", "public")));

  // I am adding this here so that the Heroku deploy will work
  // Indicates the app is behind a front-facing proxy,
  // and to use the X-Forwarded-* headers to determine the connection and the IP address of the client.
  // NOTE: X-Forwarded-* headers are easily spoofed and the detected IP addresses are unreliable.
  // trust proxy is disabled by default.
  // When enabled, Express attempts to determine the IP address of the client connected through the front-facing proxy, or series of proxies.
  // The req.ips property, then, contains an array of IP addresses the client is connected through.
  // To enable it, use the values described in the trust proxy options table.
  // The trust proxy setting is implemented using the proxy-addr package. For more information, see its documentation.
  // loopback - 127.0.0.1/8, ::1/128
  app.set("trust proxy", "loopback");
  // Create a session middleware with the given options
  // Note session data is not saved in the cookie itself, just the session ID. Session data is stored server-side.
  // Options: resave: forces the session to be saved back to the session store, even if the session was never
  //                  modified during the request. Depending on your store this may be necessary, but it can also
  //                  create race conditions where a client has two parallel requests to your server and changes made
  //                  to the session in one request may get overwritten when the other request ends, even if it made no
  //                  changes(this behavior also depends on what store you"re using).
  //          saveUnitialized: Forces a session that is uninitialized to be saved to the store. A session is uninitialized when
  //                  it is new but not modified. Choosing false is useful for implementing login sessions, reducing server storage
  //                  usage, or complying with laws that require permission before setting a cookie. Choosing false will also help with
  //                  race conditions where a client makes multiple parallel requests without a session
  //          secret: This is the secret used to sign the session ID cookie.
  //          name: The name of the session ID cookie to set in the response (and read from in the request).
  //          cookie: Please note that secure: true is a recommended option.
  //                  However, it requires an https-enabled website, i.e., HTTPS is necessary for secure cookies.
  //                  If secure is set, and you access your site over HTTP, the cookie will not be set.
  
  // TODO: Needs to init express session

  const node_env = process.env.NODE_ENV;
  console.log("--------------------------");
  console.log("===>  Starting Server . . .");
  console.log("===>  Environment: " + node_env);
  if(node_env === "production") {
    console.log("===> 🚦  Note: In order for authentication to work in production");
    console.log("===>           you will need a secure HTTPS connection");
    // sess.cookie.secure = true; // Serve secure cookies
  }
};
开发者ID:eddieLiu69,项目名称:react-webpack-node-tmpl,代码行数:58,代码来源:express.ts

示例3: configureApplication

export default function configureApplication(app: express.Application) {

    app.use(methodOverride('X-HTTP-Method-Override'));
    app.use(methodOverride('X-HTTP-Method'));

    app.use((req, res, next) => {
        logger.debug(`~ ${req.method} ${req.url}`);
        next();
    });

    app.use(compression());

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

    app.get('/', (req, res) => {
        res.json({
            NODE_ENV: process.env.NODE_ENV || '<unset>',
            accountResolver: nconf.get('accountResolver')
        });
    });

    initOAuthController(app);
    initClientsController(app);
    initAuthorizationsController(app);

    app.use((err: Error, req: express.Request, res: express.Response, next) => {
        logger.error(`${req.method} ${req.url}`, err);

        if (res.headersSent) {
            return next(err);
        }

        // TODO: maybe also check 'Accept' header?
        if (res['useErrorPageEnabled']) {
            renderError(res, err.toString());
        } else {
            jsonError(res, err);
        }
    });
}
开发者ID:itsuryev,项目名称:tp-oauth-server,代码行数:41,代码来源:configure.ts

示例4: function

export default function(app) {

  let rootPath = path.normalize(`${__dirname}/../..`);
  let clientPath: string = path.join(rootPath, 'client');

  app.use(express.static(clientPath));
  app.set('clientPath', clientPath);

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

  // let env = app.get('env');
  let env = process.env.NODE_ENV  || 'development';
  if (env === 'development') {
    app.use(errorHandler());
  }

}
开发者ID:AlanJui,项目名称:jspm-md,代码行数:19,代码来源:express.ts

示例5: configuration

 static configuration(): express.Express { 
      let app = express();
      app.use(methodOverride("X-HTTP-Method"));          
      app.use(methodOverride("X-HTTP-Method-Override")); 
      app.use(methodOverride("X-Method-Override"));      
      app.use(methodOverride("_method"));
      return app;
  }
开发者ID:fedoranimus,项目名称:typescript-mean-stack,代码行数:8,代码来源:MethodOverride.ts

示例6: newInstance

    newInstance(config: IConfig, env: string): express.Express {
        var app = express();

        app.set("views", config.root + "/server/views");
        app.set("view engine", "html");
        app.use(compression());
        app.use(bodyParser.urlencoded({ extended: false }));
        app.use(bodyParser.json());
        app.use(methodOverride());
        app.use(cookieParser());

        // Persist sessions with mongoStore / sequelizeStore
        // We need to enable sessions for passport-twitter because it"s an
        // oauth 1.0 strategy, and Lusca depends on sessions
        /*app.use(session({
            secret: config.secrets.session,
            saveUninitialized: true,
            resave: false,
            store: new mongoStore({
                mongooseConnection: mongoose.connection,
                db: "opcrates-bot-server"
            })
        }));*/

        app.set("appPath", path.join(config.root, "client"));
        app.use(morgan("dev"));
        app.use(express.static(app.get("appPath")));

        if ("development" === env || "test" === env) {
            app.use(express.static(path.join(config.root, ".tmp")));
            app.use(errorHandler()); // Error handler - has to be last
        }

        return app;
    }
开发者ID:Tmeister,项目名称:generator-typescript-express,代码行数:35,代码来源:applicationFactory.ts

示例7: preconfigExpress

export function preconfigExpress() {
  var app = express();

  if (config.ENV === 'prod') {
    app.use(compress());
  } else {
    app.use(morgan('dev'));
  }

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

  // app.use(session({
  //   saveUninitialized: true,
  //   resave: true,
  //   secret: config.SESSION_SECRET
  // }));

  // app.set('views', normalize(join(__dirname, 'src/core/server/views')));
  // app.set('view engine', 'ejs');

  route.routes(app);

  app.use(express.static(normalize(__dirname)));

  return app;
}
开发者ID:baodongliu,项目名称:mea2nt,代码行数:30,代码来源:express.ts

示例8: expressInit

// function to initialize the express app
function expressInit(app) {

  //aditional app Initializations
  app.use(bodyParser.urlencoded({
    extended: false
  }));
  app.use(bodyParser.json());
  app.use(methodOverride());
  app.use(cookieParser());
  // Initialize passport and passport session
  app.use(passport.initialize());

  //initialize morgan express logger
  // NOTE: all node and custom module requests
  if (process.env.NODE_ENV !== 'test') {
    app.use(morgan('dev', {
      skip: function (req, res) { return res.statusCode < 400 }
    }));
  }

  // app.use(session({
  //   secret: config.sessionSecret,
  //   saveUninitialized: true,
  //   resave: false,
  //   store: new MongoStore({
  //     mongooseConnection: mongoose.connection
  //   })
  // }));

  //sets the routes for all the API queries
  routes(app);

  const dist = fs.existsSync('dist');

  //exposes the client and node_modules folders to the client for file serving when client queries "/"
  app.use('/node_modules', express.static('node_modules'));
  app.use('/custom_modules', express.static('custom_modules'));
  app.use(express.static(`${dist ? 'dist/client' : 'client'}`));
  app.use('/public', express.static('public'));

  //exposes the client and node_modules folders to the client for file serving when client queries anything, * is a wildcard
  app.use('*', express.static('node_modules'));
  app.use('*', express.static('custom_modules'));
  app.use('*', express.static(`${dist ? 'dist/client' : 'client'}`));
  app.use('*', express.static('public'));

  // starts a get function when any directory is queried (* is a wildcard) by the client, 
  // sends back the index.html as a response. Angular then does the proper routing on client side
  if (process.env.NODE_ENV !== 'development')
    app.get('*', function (req, res) {
      res.sendFile(path.join(process.cwd(), `/${dist ? 'dist/client' : 'client'}/index.html`));
    });

  return app;

};
开发者ID:projectSHAI,项目名称:expressgular2,代码行数:57,代码来源:express.ts

示例9: initApp

function initApp() {
  const app: express.Express = express();
  app.use(bodyParser.json());
  app.use(methodOverride());
  app.use(cors());

  app.use('/api/games', gameRouter)

  SocketIOService.getInstance(app)
    .io.on('connection', () => {
      console.log('user connected');
    });
}
开发者ID:IsomorphicPlanningPoker,项目名称:planning-poker-api,代码行数:13,代码来源:index.ts

示例10: _setupBaseConfig

    // Configure server
    private _setupBaseConfig (): void {
        // Set up static folder
        //this.app.use(express.static(path.join(__dirname + "public")));

        // Configure our app to use body parser. It let us get the json data from POST.
        this.app.use(bodyParser.urlencoded({ extended: true }));
        this.app.use(bodyParser.json());

        // Look in urlencoded POST bodies and delete it
        this.app.use(methodOverride((req: express.Request, res: express.Response) => {
            if (req.body && typeof req.body === "object" && "_method" in req.body) {
                var method: string = req.body._method;
                delete req.body._method;

                return method;
            }
        }));
    }
开发者ID:iammen,项目名称:crud-typescript-example,代码行数:19,代码来源:ExpressApp.ts


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