UNPKG

waffle

Version:

シンプルなWEBアプリケーションフレームワークです。(ALL YOUR NODE ARE BELONG TO US)

40 lines (37 loc) 1.4 kB
/* * Copyright 2012 Katsunori Koyanagi * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ /** * @overview JSON形式のレンダリング機能を提供するアドオンです。 */ "use strict"; /** * JSON形式でのレンダリングを行うレンダラです。 * <p> * このレンダラをコントローラで指定する場合のフォーマットは&lt;prefix&gt;となります。 このレンダラはデフォルトのレンダラとして使用されます。 * </p> * * @type Function * @name Renderers#json */ exports.render = function(context, param, data, callback) { var str = JSON.stringify(data); var buf = new Buffer(str, "UTF-8"); context.res.statusCode = 200; context.res.setHeader("Content-Type", "application/json"); context.res.setHeader("Content-Length", buf.length); context.res.write(buf); callback(); };