zoukankan      html  css  js  c++  java
  • [Hapi.js] Serving static files

    hapi does not support serving static files out of the box. Instead it relies on a module called Inert. This lesson will cover serving static files using Inert's custom handlers.

    'use strict'
    var Hapi = require( 'hapi' );
    var Boom = require('boom');
    var Path = require('path');
    
    /**
     * set up server connection
     * @type {"hapi".Server}
     */
    var server = new Hapi.Server();
    server.connection( {
        host: 'localhost',
        port: 8000
    } );
    
    
    server.register( require('inert'), function(){
    
        // server an file
        server.route({
            method: 'GET',
            path: '/2.png',
            handler: {
                file: Path.join(__dirname, 'public/images/2.png')
            }
        });
    
        // server an directory
        server.route({
            method: 'GET',
            path: '/images/{param*}',
            handler: {
                directory: {
                    path: Path.join(__dirname, 'public/images')
                }
            }
        })
    });
  • 相关阅读:
    hdu1233
    zoj 3529
    hdu 2516 取石子游戏
    组合博弈理论
    博弈——sg函数的原理和优化
    博弈及sg函数
    poj2039
    hdu 1250
    C# 类的继承和访问
    C# 索引
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5225662.html
Copyright © 2011-2022 走看看