forked from google/blockly
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathserver.js
50 lines (37 loc) · 1.04 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const fs = require('fs');
const express = require('express')
const process = require('process');
const {exec} = require('child_process');
const bodyParser = require('body-parser');
var zipper = require("zip-local");
const app = express()
app.use(express.static('.'))
app.use(bodyParser.text());
app.get('/', function (req, res) {
res.send('Hello World')
})
app.post('/savetofile', function (req, res) {
//var webString = "import 'package:flutter_web/material.dart';"
var newContent = req.body;
// working dir is already sample-flutter-project
var path = "lib/main.dart";
fs.writeFile(path, newContent, function(err) {
if (err) {
return console.log(err);
}
console.log("Saved file.");
});
res.send(req.body);
})
process.chdir("sample-flutter-project");
//startWebDevServe()
app.listen(3000)
function startWebDevServe() {
exec("webdev serve", (err, stdout, stderr) => {
if (err) {
console.log(err);
}
console.log(stdout);
});
console.log("Starting webdev serve");
}