diff --git a/.gitignore b/.gitignore
index 410bdf4..ac03711 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,8 +28,9 @@ node_modules
.lock-wscript
# API credentials file
-credentials.js
+run.bat
+run.sh
# webstorm project files
.idea
-credentials_.js
+
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..cf5deb9
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,6 @@
+language: node_js
+node_js:
+ - "0.12"
+ - "0.11"
+ - "0.10"
+
diff --git a/README-option.md b/README-option.md
index 6396a6a..1de7cfd 100644
--- a/README-option.md
+++ b/README-option.md
@@ -24,17 +24,7 @@ get model URNs - as explained in the Setup/Usage Instructions.
## Setup/Usage Instructions
-* From the sample root folder, rename or copy the ./credentials_.js file into ./credentials.js
- * Windows
- ```
- copy credentials_.js credentials.js
- ```
- * OSX/Linux
- ```
- cp credentials_.js credentials.js
- ```
-* The [upload tool](http://still-spire-1606.herokuapp.com) provides some existing models. Choose any one of them, or upload one of your own
- models with [upload tool](http://still-spire-1606.herokuapp.com). The [upload tool](http://still-spire-1606.herokuapp.com) will generate a URN of the model that you need later.
+* The [upload tool](http://still-spire-1606.herokuapp.com) provides some existing models. Choose any one of them, or upload one of your own models with [upload tool](http://still-spire-1606.herokuapp.com). The [upload tool](http://still-spire-1606.herokuapp.com) will generate a URN of the model that you need later.
* Copy the URN which was generated in the previous step in file /www/index.js at line #18
```
var defaultUrn = '';
diff --git a/README-stg.md b/README-stg.md
index 56bacc1..485baf3 100644
--- a/README-stg.md
+++ b/README-stg.md
@@ -34,29 +34,21 @@ get model URNs - as explained in the Setup/Usage Instructions.
## Setup/Usage Instructions
* Apply for your own credentials (API keys) from [http://developer-stg.autodesk.com](http://developer-stg.autodesk.com)
-* From the sample root folder, rename or copy the ./credentials_.js file into ./credentials.js
- * Windows
- ```
- copy credentials_.js credentials.js
- ```
- * OSX/Linux
- ```
- cp credentials_.js credentials.js
- ```
-* Replace the placeholder with your own keys in credentials.js, line #23 and #24
- ```
- credentials.ClientId = '';
-
- credentials.ClientSecret = '';
- ```
-* In file credentials.js line #26, replace the BaseUrl address by the staging server address
+* Replace the placeholder with your own keys in run.sh(for Mac/Linux) or run.bat(for Windows),
+
```
- credentials.BaseUrl = 'https://developer-stg.api.autodesk.com' ;
+ConsumerKey=replace_with_your_consumer_key \
+ConsumerSecret=replace_with_your_secret_key \
+BaseUrl=https://developer-stg.api.autodesk.com \
+node server.js
```
+
* Upload one of your models to your account and get its URN using another workflow sample, for example,
- [this workflow sample in .Net WPF application](https://github.com/Developer-Autodesk/workflow-wpf-view.and.data.api) if you are using windows
- - or [this workflow sample in Mac OS Swift](https://github.com/Developer-Autodesk/workflow-macos-swift-view.and.data.api) if you are using Mac
- - or this [WEB page](http://javalmvwalkthrough-vq2mmximxb.elasticbeanstalk.com/)
+ - or [this workflow sample in Mac OS Swift](https://github.com/Developer-Autodesk/workflow-macos-swift-view.and.data.api) if you are using Mac.
+
+ Please note that you also need to change the base url to https://developer-stg.api.autodesk.com and replace your consumer key and secret on staging.
+
* Copy the URN which was generated in the previous step in file /www/index.js at line #18
```
var defaultUrn = '';
@@ -68,10 +60,19 @@ get model URNs - as explained in the Setup/Usage Instructions.
```
* In file /www/index.js, comment out line #23, and uncomment line #24
-* Run the server from the Node.js console, by running the following command:
+* Run the server from the Node.js console, by running the following command(For Mac):
+
+ ```
+ $ chmod +x run.sh
+ $ ./run.sh
+ ```
+
+ For windows, run the "run.bat" from command window
+
```
- node server.js
+ run.bat
```
+
* Connect to you local server using a WebGL-compatible browser: [http://localhost:3000/](http://localhost:3000/)
diff --git a/README.md b/README.md
index 890eed8..253cf40 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,8 @@
# Autodesk View and Data API Node.js Basic Sample
+[](https://api.travis-ci.org/duchangyu/workflow-node.js-view.and.data.api)
+
+
## Description
A sample demonstrating how to view a model in a web application with the Autodesk View & Data API. This web application has a basic Node.js
@@ -25,32 +28,35 @@ get model URNs - as explained in the Setup/Usage Instructions.
## Setup/Usage Instructions
* Apply for your own credentials (API keys) from [http://developer.autodesk.com](http://developer.autodesk.com)
-* From the sample root folder, rename or copy the ./credentials_.js file into ./credentials.js
- * Windows
- ```
- copy credentials_.js credentials.js
- ```
- * OSX/Linux
- ```
- cp credentials_.js credentials.js
- ```
-* Replace the placeholder with your own keys in credentials.js, line #23 and #24
+
+* Replace the placeholder with your own keys in run.sh(for Mac/Linux) or run.bat(for Windows),
+
```
- credentials.ClientId = '';
-
- credentials.ClientSecret = '';
+ConsumerKey=replace_with_your_consumer_key \
+ConsumerSecret=replace_with_your_secret_key \
+BaseUrl=https://developer.api.autodesk.com \
+node server.js
```
* Upload one of your models to your account and get its URN using another workflow sample, for example,
- [this workflow sample in .Net WPF application](https://github.com/Developer-Autodesk/workflow-wpf-view.and.data.api) if you are using windows
- or [this workflow sample in Mac OS Swift](https://github.com/Developer-Autodesk/workflow-macos-swift-view.and.data.api) if you are using Mac
- - or this [WEB page](http://javalmvwalkthrough-vq2mmximxb.elasticbeanstalk.com/)
-* Copy the URN which was generated in the previous step in file /www/index.js at line #18
+ - or this [WEB page](http://models.autodesk.io)
+* Copy the URN which was generated in the previous step in file /www/index.js at line #18
+
```
- var defaultUrn = '';
+ var defaultUrn = 'replace with your encoded urn';
```
-* Run the server from the Node.js console, by running the following command:
+* Run the server from the Node.js console, by running the following command(For Mac):
+
+ ```
+ $ chmod +x run.sh
+ $ ./run.sh
+ ```
+
+ For windows, run the "run.bat" from command window
+
```
- node server.js
+ run.bat
```
* Connect to you local server using a WebGL-compatible browser: [http://localhost:3000/](http://localhost:3000/)
@@ -62,12 +68,12 @@ By default, the project is setup with the production server, and use your own cr
You can work with production or staging Autodesk View and Data environments. By default, the project is setup with the production server.
-* Instructions to setup this sample to use the Autodesk View & Data staging server are [here](https://github.com/Developer-Autodesk/workflow-node.js-view.and.data.api/blob/master/README-stg.md)
+* Instructions to setup this sample to use the Autodesk View & Data staging server are [here](README-stg.md)
-You can also use someone else credentials to view models using this sample.
+If you are in a hurry, do not want to translate your own models, you can try our prepared models. You need use the access token generated from someone else credentials to view models using this sample.
-* Instructions to setup this sample using someone else credentials are available [here](https://github.com/Developer-Autodesk/workflow-node.js-view.and.data.api/blob/master/README-option.md)
+* Instructions to setup this sample using someone else credentials are available [here](README-option.md)
## License
diff --git a/credentials_.js b/credentials_.js
deleted file mode 100644
index 7faa047..0000000
--- a/credentials_.js
+++ /dev/null
@@ -1,29 +0,0 @@
-/////////////////////////////////////////////////////////////////////////////////
-// Copyright (c) Autodesk, Inc. All rights reserved
-// Written by Philippe Leefsma 2014 - ADN/Developer Technical Services
-//
-// Permission to use, copy, modify, and distribute this software in
-// object code form for any purpose and without fee is hereby granted,
-// provided that the above copyright notice appears in all copies and
-// that both that copyright notice and the limited warranty and
-// restricted rights notice below appear in all supporting
-// documentation.
-//
-// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
-// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
-// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
-// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
-// UNINTERRUPTED OR ERROR FREE.
-/////////////////////////////////////////////////////////////////////////////////
-
-var credentials ={} ;
-
-// Replace placeholder below by the Consumer Key and Consumer Secret you got from
-// http://developer.autodesk.com/ for the production server
-credentials.ClientId ='' ;
-credentials.ClientSecret ='' ;
-
-// If you which to use the Autodesk View & Data API on the staging server, change this url
-credentials.BaseUrl = 'https://developer.api.autodesk.com' ;
-
-module.exports =credentials ;
diff --git a/package.json b/package.json
index ca31ca7..383cc25 100644
--- a/package.json
+++ b/package.json
@@ -24,6 +24,7 @@
"serve-favicon": "*",
"stringstream": "0.0.4",
"tough-cookie": "^0.13.0",
- "tunnel-agent": "^0.4.0"
+ "tunnel-agent": "^0.4.0",
+ "cors" : "*"
}
}
diff --git a/routes/api.js b/routes/api.js
index 408f063..a8135f9 100644
--- a/routes/api.js
+++ b/routes/api.js
@@ -15,29 +15,72 @@
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
/////////////////////////////////////////////////////////////////////////////////
-var credentials = require('../credentials');
var express = require('express');
var request = require('request');
var router = express.Router();
+var cors = require('cors');
+
+var corsOptions = {
+ origin: 'http://secure-token.herokuapp.com'
+};
+
+router.get('/tokenadsk', function (req, res) {
+
+ //steals access token from http://secure-token.herokuapp.com
+ request('http://secure-token.herokuapp.com/api/token',
+ function (error, response, body) {
+ if (!error && response.statusCode == 200) {
+ res.send(body);
+ }
+ });
+});
+
+
+
///////////////////////////////////////////////////////////////////////////////
// Generates access token
///////////////////////////////////////////////////////////////////////////////
-router.get('/token', function (req, res) {
+router.get('/token', cors(corsOptions),function (req, res) {
var params = {
- client_id: credentials.ClientId,
- client_secret: credentials.ClientSecret,
+ client_id: process.env.ConsumerKey ,
+ client_secret: process.env.ConsumerSecret,
grant_type: 'client_credentials'
}
+ // var thisHost = req.headers.refer;//req.protocol + '://' + req.get('host');
+ //var appHost = 'http://secure-token.herokuapp.com';
+
+ // if (thisHost != appHost) {
+ // var strMsg = ' request host: ' + thisHost;
+ // strMsg = strMsg + ' app host: ' + appHost;
+ // res.send('host restricted.' + strMsg);
+ // return;
+ // }
+
+
request.post(
- credentials.BaseUrl + '/authentication/v1/authenticate',
+ process.env.BaseUrl + '/authentication/v1/authenticate',
{ form: params },
function (error, response, body) {
if (!error && response.statusCode == 200) {
+
+ // Website you wish to allow to connect
+ //res.setHeader('Access-Control-Allow-Origin', appHost);
+
+ // Request methods you wish to allow
+ //res.setHeader('Access-Control-Allow-Methods', 'GET');
+
+ // // Request headers you wish to allow
+ // res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
+
+ // // Set to true if you need the website to include cookies in the requests sent
+ // // to the API (e.g. in case you use sessions)
+ // res.setHeader('Access-Control-Allow-Credentials', true);
+
res.send(body);
}
});
diff --git a/run.bat b/run.bat
new file mode 100644
index 0000000..15e7fef
--- /dev/null
+++ b/run.bat
@@ -0,0 +1,4 @@
+set ConsumerKey=
+set ConsumerSecret=
+set BaseUrl=https://developer.api.autodesk.com
+node server.js
diff --git a/run.sh b/run.sh
new file mode 100755
index 0000000..fd6584b
--- /dev/null
+++ b/run.sh
@@ -0,0 +1,4 @@
+ConsumerKey=VAgANZ4aiHITHoGeGLzv0oBtMAlFBeUa \
+ConsumerSecret=9kfkcETJZI4Blre2 \
+BaseUrl=https://developer.api.autodesk.com \
+node server.js
\ No newline at end of file
diff --git a/server.js b/server.js
index 989f4cf..4350ea8 100644
--- a/server.js
+++ b/server.js
@@ -15,15 +15,18 @@
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
/////////////////////////////////////////////////////////////////////////////////
+
var favicon = require('serve-favicon');
var api = require('./routes/api');
var express = require('express');
+var cors = require('cors');
var app = express();
app.use('/', express.static(__dirname + '/www'));
app.use(favicon(__dirname + '/www/images/favicon.ico'));
app.use('/api', api);
+app.use(cors);
app.set('port', process.env.PORT || 3000);
diff --git a/www/index.js b/www/index.js
index 7274ef9..5e06162 100644
--- a/www/index.js
+++ b/www/index.js
@@ -15,7 +15,7 @@
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
/////////////////////////////////////////////////////////////////////////////////
-var defaultUrn = '';
+var defaultUrn = 'dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6bW9kZWwyMDE1LTA1LTExLTA5LTE2LTEwLWdlN3B4aXNzNDF0eGRqdHhxa3R4eTN3MWc2emUvUm9ib3RBcm0uZHdmeA==';
$(document).ready(function () {
var tokenurl = 'http://' + window.location.host + '/api/token';