PR 1: Merge feature/azure to master
- Add dependencies to Azure services - Add in a route which reads a file from blob storage
This commit is contained in:
Родитель
5867b64f59
Коммит
719a194571
|
@ -5,6 +5,9 @@ Requirements
|
|||
* Node.js
|
||||
|
||||
Project setup
|
||||
* `npm install -g typescript gulp-cli`
|
||||
* `npm install -g typescript gulp-cli typings`
|
||||
* `npm install`
|
||||
|
||||
Running
|
||||
* `node dist\www.js`
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"documentDB": "AccountEndpoint=https://officenet.documents.azure.com:443/;AccountKey=P8Ynaoa5nQLdwq97n7UZ0XI4Rq61ELKKTXt8a9sSkyb77NJdCSTxov76uVdEQDKzBwDQV04277BzYn7tLaBRXQ==;",
|
||||
"blob": {
|
||||
"name": "officenet",
|
||||
"key": "74sWUSWijrNfAe5gKp7jH+2uVsbPNSjNiBLC01BIMa7T2RimQNX0n8F1+hNPys/wUVb9827qiaipWlQslghWfA=="
|
||||
}
|
||||
}
|
|
@ -5,7 +5,8 @@
|
|||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "node ./dist/www"
|
||||
"start": "node ./dist/www",
|
||||
"postinstall": "typings install"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -13,13 +14,21 @@
|
|||
},
|
||||
"author": "",
|
||||
"dependencies": {
|
||||
"azure-storage": "^1.3.1",
|
||||
"body-parser": "~1.13.2",
|
||||
"cookie-parser": "~1.3.5",
|
||||
"debug": "~2.2.0",
|
||||
"documentdb": "^1.9.0",
|
||||
"es6-promise": "^3.3.1",
|
||||
"es6-promisify": "^4.1.0",
|
||||
"express": "~4.13.1",
|
||||
"express-session": "^1.14.1",
|
||||
"hjs": "~0.0.6",
|
||||
"less-middleware": "1.0.x",
|
||||
"morgan": "~1.6.1",
|
||||
"nconf": "^0.8.4",
|
||||
"passport": "^0.3.2",
|
||||
"passport-openidconnect": "0.0.1",
|
||||
"serve-favicon": "~2.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -7,6 +7,7 @@ var bodyParser = require('body-parser');
|
|||
|
||||
var routes = require('./routes/index');
|
||||
var users = require('./routes/users');
|
||||
import * as knowledgeRoute from './routes/knowledge';
|
||||
|
||||
var app = express();
|
||||
|
||||
|
@ -31,16 +32,12 @@ app.use((request, response, next) => {
|
|||
});
|
||||
app.use('/', routes);
|
||||
app.use('/users', users);
|
||||
|
||||
// Let TypeScript know Express adds in a status code to errors
|
||||
interface Error{
|
||||
status?: number;
|
||||
}
|
||||
app.use('/knowledge', knowledgeRoute);
|
||||
|
||||
// catch 404 and forward to error handler
|
||||
app.use(function(req, res, next) {
|
||||
var err = new Error('Not Found');
|
||||
err.status = 404;
|
||||
(<any> err).status = 404;
|
||||
next(err);
|
||||
});
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
import * as express from 'express';
|
||||
|
||||
// import * as storage from 'azure-storage';
|
||||
var nconf = require('nconf');
|
||||
var storage = require('azure-storage');
|
||||
var promisify = require('es6-promisify');
|
||||
|
||||
// Create access to blob storage
|
||||
var connectionInfo = nconf.get('blob');
|
||||
var blobService = storage.createBlobService(connectionInfo.name, connectionInfo.key);
|
||||
|
||||
var router = express.Router();
|
||||
|
||||
// Create promise specific versions of storage commands
|
||||
var getBlobToText = promisify(blobService.getBlobToText, blobService);
|
||||
|
||||
router.get('/:id', (request: express.Request, response: express.Response, next: express.NextFunction) => {
|
||||
var id = request.params['id'];
|
||||
var textP = getBlobToText('knowledge', id)
|
||||
|
||||
textP.then(
|
||||
(result) => {
|
||||
response.json(JSON.parse(result));
|
||||
},
|
||||
(error) => {
|
||||
response.status(400).json(error);
|
||||
});
|
||||
});
|
||||
|
||||
export = router;
|
|
@ -1,9 +1,14 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
// Load in configuration first before resolving other modules
|
||||
import * as path from 'path';
|
||||
var nconf = require('nconf');
|
||||
// Setup the configuration system - pull arguments, then environment variables
|
||||
nconf.argv().env().file(path.join(__dirname, '../config.json')).use('memory');
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var app = require('./app');
|
||||
var debug = require('debug')('tmp:server');
|
||||
var http = require('http');
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
{
|
||||
"globalDependencies": {
|
||||
"node": "registry:env/node#4.0.0+20160918225031"
|
||||
},
|
||||
"dependencies": {
|
||||
"documentdb": "registry:npm/documentdb#1.8.0+20160622193850",
|
||||
"es6-promise": "registry:npm/es6-promise#3.0.0+20160723033700",
|
||||
"express": "registry:npm/express#4.14.0+20160911114220"
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче