-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gael Leblan
committed
Jul 21, 2020
1 parent
8a6469f
commit 7a8382d
Showing
5 changed files
with
777 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,54 @@ | ||
const http = require('http'); | ||
const fileUpload = require('express-fileupload'); | ||
|
||
const hostname = '127.0.0.1'; | ||
const port = 3000; | ||
|
||
const server = http.createServer((req, res) => { | ||
res.statusCode = 200; | ||
res.setHeader('Content-Type', 'text/plain'); | ||
res.end('Hello World'); | ||
const nodeSlicer = require('node-slic3r'); | ||
|
||
const express = require('express') | ||
const app = express() | ||
const fs = require('fs'); | ||
// default options | ||
app.use(fileUpload()); | ||
|
||
app.get('/', function (req, res) { | ||
res.send('Hello World!') | ||
}) | ||
|
||
app.post('/upload', function(req, res) { | ||
console.log(req.files); | ||
|
||
for(var i = 0 ; i < Object.keys(req.files).length; i++) { | ||
var nameObject = Object.keys(req.files)[i]; | ||
var sampleFile = req.files[nameObject]; | ||
// Use the mv() method to place the file somewhere on your server | ||
sampleFile.mv('/tmp/' + sampleFile.name, function(err) { | ||
if (err) | ||
return res.status(500).send(err); | ||
|
||
var options = { | ||
inputFile: '/tmp/' + sampleFile.name | ||
// For more options check out the configSchema.yaml file | ||
}; | ||
|
||
nodeSlicer.render(options, function (error, bufferData) { | ||
if (error) | ||
console.error(error.message) | ||
else { | ||
console.log(sampleFile.name); | ||
let name = sampleFile.name.substring(0, sampleFile.name.lastIndexOf('.')); | ||
console.log(name); | ||
fs.writeFile('/tmp/' + name + '.gcode', bufferData, function (err) { | ||
if (err) throw err; | ||
res.download('/tmp/' + name + '.gcode', name + '.gcode'); | ||
}); | ||
} | ||
}) | ||
}); | ||
} | ||
}); | ||
|
||
server.listen(port, hostname, () => { | ||
app.listen(port, hostname, () => { | ||
console.log(`Server running at http://${hostname}:${port}/`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
0 info it worked if it ends with ok | ||
1 verbose cli [ '/home/Gael.Leblan/.nvm/versions/node/v4.1.2/bin/node', | ||
1 verbose cli '/home/Gael.Leblan/.nvm/versions/node/v4.1.2/bin/npm', | ||
1 verbose cli 'run', | ||
1 verbose cli 'dev' ] | ||
2 info using [email protected] | ||
3 info using [email protected] | ||
4 verbose run-script [ 'predev', 'dev', 'postdev' ] | ||
5 info predev [email protected] | ||
6 info dev [email protected] | ||
7 verbose unsafe-perm in lifecycle true | ||
8 info [email protected] Failed to exec dev script | ||
9 verbose stack Error: [email protected] dev: `node app.js` | ||
9 verbose stack Exit status 1 | ||
9 verbose stack at EventEmitter.<anonymous> (/home/Gael.Leblan/.nvm/versions/node/v4.1.2/lib/node_modules/npm/lib/utils/lifecycle.js:214:16) | ||
9 verbose stack at emitTwo (events.js:87:13) | ||
9 verbose stack at EventEmitter.emit (events.js:172:7) | ||
9 verbose stack at ChildProcess.<anonymous> (/home/Gael.Leblan/.nvm/versions/node/v4.1.2/lib/node_modules/npm/lib/utils/spawn.js:24:14) | ||
9 verbose stack at emitTwo (events.js:87:13) | ||
9 verbose stack at ChildProcess.emit (events.js:172:7) | ||
9 verbose stack at maybeClose (internal/child_process.js:818:16) | ||
9 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5) | ||
10 verbose pkgid [email protected] | ||
11 verbose cwd /home/Gael.Leblan/Workspace/perso/BaldrSlicer/baldr-api | ||
12 error Linux 4.15.0-109-generic | ||
13 error argv "/home/Gael.Leblan/.nvm/versions/node/v4.1.2/bin/node" "/home/Gael.Leblan/.nvm/versions/node/v4.1.2/bin/npm" "run" "dev" | ||
14 error node v4.1.2 | ||
15 error npm v2.14.4 | ||
16 error code ELIFECYCLE | ||
17 error [email protected] dev: `node app.js` | ||
17 error Exit status 1 | ||
18 error Failed at the [email protected] dev script 'node app.js'. | ||
18 error This is most likely a problem with the baldr-api package, | ||
18 error not with npm itself. | ||
18 error Tell the author that this fails on your system: | ||
18 error node app.js | ||
18 error You can get their info via: | ||
18 error npm owner ls baldr-api | ||
18 error There is likely additional logging output above. | ||
19 verbose exit [ 1, true ] |
Oops, something went wrong.