Initial web service for oav-express

This commit is contained in:
Vishrut Shah 2017-04-17 21:56:11 -07:00
Родитель fa17e11eed
Коммит 9b8cf0c515
6 изменённых файлов: 145 добавлений и 0 удалений

21
.vscode/launch.json поставляемый Normal file
Просмотреть файл

@ -0,0 +1,21 @@
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceRoot}/index.js"
},
{
"type": "node",
"request": "attach",
"name": "Attach to Port",
"address": "localhost",
"port": 5858
}
]
}

13
.vscode/settings.json поставляемый Normal file
Просмотреть файл

@ -0,0 +1,13 @@
{
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.DS_Store": true
},
"[javascript]": {
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"editor.tabSize": 2,
"editor.detectIndentation": false
}
}

Просмотреть файл

@ -1,3 +1,5 @@
# oav-express web service
# Contributing # Contributing
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.

56
index.js Normal file
Просмотреть файл

@ -0,0 +1,56 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
'use strict';
var oav = require('oav');
var express = require('express');
var bodyParser = require('body-parser');
var multer = require('multer');
var ErrorCodes = oav.Constants.ErrorCodes;
var port = process.env.PORT || 1337;
var server;
var app = express();
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
// LiveValidator configuration options
let options = {
"git": {
"shouldClone": true,
"url": "https://github.com/Azure/azure-rest-api-specs.git"
}
};
const validator = new oav.LiveValidator(options);
validator.initialize().then(() => {
console.log("Live validator initialized.");
server = app.listen(port, () => {
var host = server.address().address
var port = server.address().port
console.log("Example app listening at http://%s:%s", host, port);
});
});
app.get('/', function (req, res) {
res.send('Welcome to oav-express');
})
// This responds a POST request for live validation
app.post('/validate', function (req, res) {
let validationResult = validator.validateLiveRequestResponse(req.body);
// Something went wrong
if (validationResult && validationResult.errors && Array.isArray(validationResult.errors) && validationResult.errors.length) {
let errors = validationResult.errors;
let is400 = errors.some((error) => { return error.code === ErrorCodes.IncorrectInput });
if (is400) {
// Return 400 with validationResult
return res.send(400, validationResult);
}
}
// Return 200 with validationResult
return res.send(validationResult);
});

40
package.json Normal file
Просмотреть файл

@ -0,0 +1,40 @@
{
"name": "oav-express",
"version": "0.0.1",
"author": {
"name": "Microsoft Corporation",
"email": "azsdkteam@microsoft.com",
"url": "https://github.com/azure/oav-express"
},
"description": "Web service for live request validation using oav",
"homepage": "https://github.com/azure/oav-express",
"repository": {
"type": "git",
"url": "https://github.com/Azure/oav-express.git"
},
"bugs": {
"url": "https://github.com/Azure/oav-express/issues"
},
"license": "MIT",
"dependencies": {
"oav": "azure/oav#master",
"express": "^4.15.2",
"cookie-parser": "^1.4.3",
"multer": "^1.3.0"
},
"devDependencies": {
"jshint": "2.9.4",
"mocha": "^3.2.0",
"should": "5.2.0",
"@types/mocha": "^2.2.40",
"@types/should": "^8.1.30"
},
"engines": {
"node": ">=6.9.1"
},
"scripts": {
"start": "node index.js",
"test": "mocha -t 50000"
},
"main": "./index.js"
}

13
process.json Normal file
Просмотреть файл

@ -0,0 +1,13 @@
{
"name": "worker",
"script": "./index.js",
"instances": 1,
"merge_logs": true,
"log_date_format": "YYYY-MM-DD HH:mm Z",
"watch": true,
"watch_options": {
"followSymlinks": true,
"usePolling": true,
"interval": 5
}
}