我正在编写一个提供静态html,css和javascript的小型演示Web服务器.服务器看起来像
(function () {
"use strict";
var http = require("http");
var connect = require('connect');
var app = connect()
.use(connect.logger('dev'))
.use(connect.static('home'));
var server = http.createServer(app);
server.listen(9999, function () {
console.log('server is listening');
});
})();
Run Code Online (Sandbox Code Playgroud)
我的客户端javascript使ajax调用到不同的服务器.我该如何添加
Access-Control-Allow-Origin: http://example.com
Run Code Online (Sandbox Code Playgroud)
到我的服务器响应,以便客户端javascript可以进行ajax调用?
我正在使用节点和表达.要注册控制器我打电话:
app.get('/user/:id', function (req, res) {...});
Run Code Online (Sandbox Code Playgroud)
但我想用rfc-6570方式做到这一点:
app.get('/user/{id}', function (req, res) {...});
Run Code Online (Sandbox Code Playgroud)
我在谷歌代码上搜索了python中的一个实现,但没有找到任何内容(除了谷歌代码上的死链接到http://www.snellspace.com/wp/?p=831).
一般来说,URI模板并不像第一眼看上去那么容易.看看RFC中的示例.
PS:我也需要客户端上的URI模板.
例:
import com.google.gson.Gson;
class GsonDemo {
private static class Static {String key = "static";}
private class NotStatic {String key = "not static";}
void testGson() {
Gson gson = new Gson();
System.out.println(gson.toJson(new Static()));
// expected = actual: {"key":"static"}
System.out.println(gson.toJson(new NotStatic()));
// expected = actual: {"key":"not static"}
class MethodLocal {String key = "method local";}
System.out.println(gson.toJson(new MethodLocal()));
// expected: {"key":"method local"}
// actual: null (be aware: the String "null")
Object extendsObject = new Object() {String key = "extends Object";};
System.out.println(gson.toJson(extendsObject));
// expected: {"key":"extends …Run Code Online (Sandbox Code Playgroud)