kopia lustrzana https://github.com/c9/core
add mock for persistent data api
rodzic
fe256bc086
commit
1325a510fc
|
@ -183,7 +183,6 @@ function plugin(options, imports, register) {
|
||||||
|
|
||||||
api.get("/configs/require_config.js", function(req, res, next) {
|
api.get("/configs/require_config.js", function(req, res, next) {
|
||||||
var config = res.getOptions().requirejsConfig || {};
|
var config = res.getOptions().requirejsConfig || {};
|
||||||
config.waitSeconds = 240;
|
|
||||||
|
|
||||||
res.writeHead(200, {"Content-Type": "application/javascript"});
|
res.writeHead(200, {"Content-Type": "application/javascript"});
|
||||||
res.end("requirejs.config(" + JSON.stringify(config) + ");");
|
res.end("requirejs.config(" + JSON.stringify(config) + ");");
|
||||||
|
@ -212,6 +211,54 @@ function plugin(options, imports, register) {
|
||||||
|
|
||||||
api.get("/api.json", {name: "api"}, frontdoor.middleware.describeApi(api));
|
api.get("/api.json", {name: "api"}, frontdoor.middleware.describeApi(api));
|
||||||
|
|
||||||
|
api.get("/api/project/:pid/persistent/:apikey", {
|
||||||
|
params: {
|
||||||
|
pid: { type: "number" },
|
||||||
|
apikey: { type: "string" }
|
||||||
|
}
|
||||||
|
}, persistentDataApiMock);
|
||||||
|
api.put("/api/project/:pid/persistent/:apikey", {
|
||||||
|
params: {
|
||||||
|
data: { type: "string", source: "body" },
|
||||||
|
pid: { type: "number" },
|
||||||
|
apikey: { type: "string" },
|
||||||
|
}
|
||||||
|
}, persistentDataApiMock);
|
||||||
|
api.get("/api/user/persistent/:apikey", {
|
||||||
|
params: {
|
||||||
|
apikey: { type: "string" }
|
||||||
|
}
|
||||||
|
}, persistentDataApiMock);
|
||||||
|
api.put("/api/user/persistent/:apikey", {
|
||||||
|
params: {
|
||||||
|
data: { type: "string", source: "body" },
|
||||||
|
apikey: { type: "string" },
|
||||||
|
}
|
||||||
|
}, persistentDataApiMock);
|
||||||
|
|
||||||
|
function persistentDataApiMock(req, res, next) {
|
||||||
|
var name = (req.params.pid || 0) + "-" + req.params.apikey;
|
||||||
|
var data = req.params.data;
|
||||||
|
console.log(name, data)
|
||||||
|
if (/[^\w+=\-]/.test(name))
|
||||||
|
return next(new Error("Invalid apikey"));
|
||||||
|
var path = join(options.installPath, ".c9", "persistent");
|
||||||
|
var method = req.method.toLowerCase()
|
||||||
|
if (method == "get") {
|
||||||
|
res.writeHead(200, {"Content-Type": "application/octet-stream"});
|
||||||
|
var stream = fs.createReadStream(path + "/" + name);
|
||||||
|
stream.pipe(res);
|
||||||
|
} else if (method == "put") {
|
||||||
|
require("mkdirp")(path, function(e) {
|
||||||
|
fs.writeFile(path + "/" + name, data, "", function(err) {
|
||||||
|
if (err) return next(err);
|
||||||
|
res.writeHead(200, {"Content-Type": "application/octet-stream"});
|
||||||
|
res.end("");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// fake authentication
|
// fake authentication
|
||||||
api.authenticate = api.authenticate || function() {
|
api.authenticate = api.authenticate || function() {
|
||||||
return function(req, res, next) {
|
return function(req, res, next) {
|
||||||
|
|
|
@ -63,7 +63,7 @@ module.exports = function(manifest, installPath) {
|
||||||
ideBaseUrl: "http://c9.io",
|
ideBaseUrl: "http://c9.io",
|
||||||
previewUrl: "/preview",
|
previewUrl: "/preview",
|
||||||
dashboardUrl: "https://c9.io/dashboard.html",
|
dashboardUrl: "https://c9.io/dashboard.html",
|
||||||
apiUrl: "https://api.c9.dev",
|
apiUrl: "/api",
|
||||||
homeUrl: "/home",
|
homeUrl: "/home",
|
||||||
collab: false,
|
collab: false,
|
||||||
installed: true,
|
installed: true,
|
||||||
|
|
Ładowanie…
Reference in New Issue