Skip to content

Commit

Permalink
parsing incomming message, docker with npm
Browse files Browse the repository at this point in the history
  • Loading branch information
pan261 committed Jan 20, 2022
1 parent e4250f1 commit 0e61ae5
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 41 deletions.
66 changes: 33 additions & 33 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,38 @@ services:
network_mode: host
command: "node taskRunner.js gantry"

task_runner_lathe:
build:
context: .
dockerfile: Dockerfile
env_file: ./.env
volumes:
- ./src/build:/ffs/
- /ffs/node_modules
- ${LOCAL_DIR_LATHE}:/ffs/FileShare/Lathe
network_mode: host
command: "node taskRunner.js lathe"
# task_runner_lathe:
# build:
# context: .
# dockerfile: Dockerfile
# env_file: ./.env
# volumes:
# - ./src/build:/ffs/
# - /ffs/node_modules
# - ${LOCAL_DIR_LATHE}:/ffs/FileShare/Lathe
# network_mode: host
# command: "node taskRunner.js lathe"

task_runner_mill:
build:
context: .
dockerfile: Dockerfile
env_file: ./.env
volumes:
- ./src/build:/ffs/
- /ffs/node_modules
- ${LOCAL_DIR_MILL}:/ffs/FileShare/Mill
network_mode: host
command: "node taskRunner.js mill"
# task_runner_mill:
# build:
# context: .
# dockerfile: Dockerfile
# env_file: ./.env
# volumes:
# - ./src/build:/ffs/
# - /ffs/node_modules
# - ${LOCAL_DIR_MILL}:/ffs/FileShare/Mill
# network_mode: host
# command: "node taskRunner.js mill"

task_runner_waterjet:
build:
context: .
dockerfile: Dockerfile
env_file: ./.env
volumes:
- ./src/build:/ffs/
- /ffs/node_modules
- ${LOCAL_DIR_WATERJET}:/ffs/FileShare/Waterjet
network_mode: host
command: "node taskRunner.js waterjet"
# task_runner_waterjet:
# build:
# context: .
# dockerfile: Dockerfile
# env_file: ./.env
# volumes:
# - ./src/build:/ffs/
# - /ffs/node_modules
# - ${LOCAL_DIR_WATERJET}:/ffs/FileShare/Waterjet
# network_mode: host
# command: "node taskRunner.js waterjet"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"start": "node /src/server.js",
"test": "echo \"Error: no test specified\" && exit 1",
"tsc": "tsc",
"docker:build": "tsc && docker-compose up --build"
"docker:build": "tsc && docker-compose up --build --remove-orphans"
},
"repository": {
"type": "git",
Expand Down
21 changes: 19 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import express = require('express');
import * as config from './config';
const fs = require('fs');


/**
Expand Down Expand Up @@ -100,8 +101,24 @@ const createServer = () => {
});

app.post('/hook', function (req: any, res: any) {
console.log(req.body);
res.status(200).end;
// console.log(req.data);
// console.log(req.payload);
// console.log(req.res);
// fs.writeFile(__dirname + '/FileShare/res.json', req, (err: any) => {
// if (err) {
// throw err;
// }
// })
let body: any = [];
req.on('error', (err: any) => {
console.error(err);
}).on('data', (chunk: any) => {
body.push(chunk);
}).on('end', () => {
body = Buffer.concat(body).toString();
console.log(body)
})
res.status(204).send();
});

// Default endpoint
Expand Down
5 changes: 5 additions & 0 deletions src/taskRunner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const axios = require('axios');
const watcher = require('./watcher');
const watcher2 = require('./watcher2')
const downloader = require('./downloader');
const fs = require('fs');
import * as config from './config';
Expand Down Expand Up @@ -68,6 +69,7 @@ const fetchToken = () => {
'\x1b[92mtaskRunner.js::fetchToken:',
'\x1b[0mCredentials received'
);
watcher2.createHook(credentials);
} else {
console.log(
'\x1b[96mtaskRunner.js::fetchToken:',
Expand Down Expand Up @@ -102,6 +104,9 @@ const getCredentials = () => {

getCredentials();


// Below is the previous watcher implementation

/**
* Function to dispatch the watcher
*/
Expand Down
13 changes: 8 additions & 5 deletions src/watcher2.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
// const axios = require('axios');

exports.watch = (credentials: any) => {

exports.createHook = (credentials: any) => {
const axios = require('axios');

axios({
method: 'POST',
url: 'https://developer.api.autodesk.com/webhooks/v1/systems/data/events/dm.version.added/hooks',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${credentials.access_token}`
},
body: {
callbackUrl: "http://localhost:3000/hook",
data: {
callbackUrl: "http://6ae7-128-210-106-76.ngrok.io/hook",
autoReactivateHook: false,
scope: {
folder: "urn:adsk.wipprod:fs.folder:co.IxiedfeBTOGg6NSIGQhXxQ" // Gantry folder
}
}
}).then((res: any) => {
console.log(res.data);
console.log(res);
}).catch((err: any) => {
console.log(err);
});
Expand Down

0 comments on commit 0e61ae5

Please sign in to comment.