auto-jsonp

0.0.2 • Public • Published

auto-jsonp

安裝

npm install auto-jsonp

功能

  • 自動把 get 多增加 .json 的網址。ex: app.get('/test') => app.get('/test'); app.get('/test.json');
  • 判斷當前網址是不是 .json 結尾。
  • 如果當前網址是 .json 結尾,自動把 render 改成 jsonp。

範例

var jsonp = require('jsonp'); // 必須比 express 早載入
var express = require('express');

......

var app = express();
app.use(jsonp);

......

app.get('/test', function (req, res, next) {
  res.render('index', {title: 'hello'});
});

......

瀏覽 http://localhost:3000/test

hello
Welcome to hello

瀏覽 http://localhost:3000/test.json

{"title": "hello"}

瀏覽 http://localhost:3000/test.json?callback=define

define({"title": "hello"});

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i auto-jsonp

      Weekly Downloads

      2

      Version

      0.0.2

      License

      MIT

      Last publish

      Collaborators

      • poying