UNPKG

936 BJavaScriptView Raw
1
2var express = require('express');
3var path = require('path');
4
5var app = express()
6var cors = require('cors');
7
8var bodyParser = require('body-parser');
9
10app.use(cors());
11app.use(bodyParser.json()); // for parsing application/json
12app.use(bodyParser.urlencoded({extended:true})); // for parsing application/x-www-form-urlencoded
13
14
15const pageName = process.env.PAGE;
16const moduleName = process.env.MODULE;
17const webPath = process.env.WEBPATH;
18
19
20console.log('static path,', webPath);
21app.use(express.static(webPath));
22
23
24console.log('env page,module webPath===>',pageName,moduleName,webPath);
25
26app.post('/createPage', function(req, res, next) {
27
28 console.log("received data", req.body);
29 require(path.resolve(__dirname, '../../lib/page-creator.js'))(req.body.params,pageName,moduleName);
30 res.json(req.body);
31});
32
33const port = 3000
34app.listen(port, () => {
35 console.log(`Example app listening at http://localhost:${port}`)
36})