From 202190104a1218586674cda18aa00f5fafde03e5 Mon Sep 17 00:00:00 2001 From: Riccardo Cocetta Date: Wed, 17 May 2017 11:48:02 +0100 Subject: [PATCH] Added CORS, fixed docs --- package.json | 17 +++++++++-------- server.js | 10 ++++++---- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 10172e9..b254fed 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "mockaccino", "description": "A server that mocks webservices", - "version": "0.0.5", + "version": "0.0.6", "license": "MIT", "contributors": [ { @@ -22,19 +22,20 @@ } ], "scripts": { - "test": "mocha tests/unit/libs/*.js" + "test": "mocha tests/unit/libs/*.js" }, - "repository" : { - "type" : "git", - "url" : "https://github.com/yahoo/mockaccino.git" + "repository": { + "type": "git", + "url": "https://github.com/yahoo/mockaccino.git" }, "dependencies": { + "cors": "^2.8.3", "express": "~3.3.1", - "request": "~2.21.0", "lodash": "~2.4.1", + "request": "~2.21.0", "yargs": "~3.6.0" }, "devDependencies": { - "mocha": "~1.12.0" + "mocha": "~1.12.0" } -} \ No newline at end of file +} diff --git a/server.js b/server.js index de8eeff..dd061a7 100644 --- a/server.js +++ b/server.js @@ -19,6 +19,7 @@ var path = require('path'), parent = module.parent.parent || module.parent, embedded = !!module.parent.parent, dirname = path.dirname(parent.filename), + cors = require('cors'), mockUtils = require("./utils.js")(dirname); @@ -48,7 +49,7 @@ function handleExtendEndpoint(req, res, cfgItem, key, method, cfg) { * Serves the static file associated with a key * @param {object} req The request obj * @param {object} res The response object - * @param {object} cfgItem the Config item associated with the enpoint you're treating now + * @param {object} cfgItem the Config item associated with the endpoint you're treating now * @param {string} key A key in the mockResponses object */ function serveStaticFileForKey(req, res, cfgItem, key, method) { @@ -59,11 +60,11 @@ function serveStaticFileForKey(req, res, cfgItem, key, method) { /** - * Serves the static file associated with a key + * Serves an object with a status code * @param {object} req The request obj * @param {object} res The response object - * @param {object} cfgItem the Config item associated with the enpoint you're treating now - * @param {string} key A key in the mockResponses object + * @param {number} statuscode the statuscode you want to return + * @param {object} the object to be sent */ function serveObject(req, res, statusCode, object) { log("[Mockaccino] Serving object"); @@ -169,6 +170,7 @@ function getMockserver(cfg) { app.use(express.bodyParser()); } app.use(express.logger()); + app.use(cors()); app.configure(function () { log("[Mockaccino] Creating routes");