码迷,mamicode.com
首页 > Windows程序 > 详细

[Hapi.js] Serving static files

时间:2016-02-28 22:55:46      阅读:338      评论:0      收藏:0      [点我收藏+]

标签:

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‘)
            }
        }
    })
});

 

[Hapi.js] Serving static files

标签:

原文地址:http://www.cnblogs.com/Answer1215/p/5225662.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!