Advertisement
lfed255-dev

Paste From Computer

Sep 7th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.85 KB | None | 0 0
  1.  
  2.  
  3. 'use strict';
  4.  
  5. var querystring = require('querystring');
  6. var http = require('http');
  7. var app = require('express')();
  8. var axios = require('axios');
  9. var babel = require('@babel/core');
  10.  
  11. var APIservPort = 8000;
  12. var APIservHost = '127.0.0.1';
  13. var servPort = 8002;
  14.  
  15. var babelpres = ["@babel/preset-env", "@babel/preset-react", "es2016"];
  16.  
  17. var html_base_code = '\n<!DOCTYPE html>\n<html lang="en">\n<head>\n\t<meta charset="UTF-8">\n\t<meta name="viewport" content="width=device-width, initial-scale=1.0">\n\t<meta http-equiv="X-UA-Compatible" content="ie=edge">\n\t<script src="https://cdn.jsdelivr.net/npm/react-helmet@5.2.1/lib/Helmet.min.js"></script>\n\t<script src=\'https://unpkg.com/react@16.3.1/umd/react.production.min.js\'></script>\n\t<script src=\'https://unpkg.com/react-dom@16.3.1/umd/react-dom.production.min.js\'></script>\n\t<script src=\'https://unpkg.com/react-router@5.0.0/umd/react-router.min.js\'></script>\n\t<script src=\'https://unpkg.com/react-router-dom@5.0.0/umd/react-router-dom.min.js\'></script>\n\t<title>Document</title>\n</head>\n<body>\n\t<div id="react-root></div>\n</body>\n</html>\n';
  18.  
  19. function apiRequest(props, r) {
  20. var _props$path = props.path,
  21. path = _props$path === undefined ? '/' : _props$path,
  22. _props$method = props.method,
  23. method = _props$method === undefined ? 'GET' : _props$method,
  24. _props$params = props.params,
  25. params = _props$params === undefined ? {} : _props$params,
  26. _props$headers = props.headers,
  27. headers = _props$headers === undefined ? { 'Content-Type': 'application/json' } : _props$headers;
  28.  
  29. params = querystring.stringify(params);
  30. var ret;
  31. axios({
  32. method: method,
  33. url: 'http://' + APIservHost + ':' + APIservPort + '/' + path,
  34. responseType: 'stream',
  35. headers: headers,
  36. params: params
  37. }).then(r).catch(function (err) {
  38. console.log(err);
  39. });
  40. }
  41.  
  42. // app.get("/",function(req,res) {
  43. // res.send('hi')
  44. // })
  45.  
  46.  
  47. app.get("/:pageid", async function (req, res) {
  48.  
  49. // built-in components
  50.  
  51. var response = await axios.get('http://localhost:8000/page/' + req.params.pageid, { withCredentials: true });
  52. _page_jsx_code = response.data.code;
  53.  
  54. var elements = await axios.get('http://localhost:8000/elements/', { withCredentials: true }).data;
  55.  
  56. //page_code = babel.transform(_jsx_code,{ presets: babelpres})
  57.  
  58. var jsx_ucode = "";
  59.  
  60. res.end();
  61. });
  62.  
  63. app.get("/p/:postid", async function (req, res) {
  64.  
  65. // built-in components
  66.  
  67. var post_resp_ = await axios.get('http://localhost:8000/element/' + req.params.postid, { withCredentials: true });
  68. var post = post_resp_.data;
  69.  
  70. if (!post.post) {
  71. res.send('post not found');
  72. res.end();
  73. }
  74. var post_ccode = post.code;
  75.  
  76. var ppage_resp_ = await axios.get('http://localhost:8000/page/__posth');
  77.  
  78. var ppage = ppage_resp_.data;
  79.  
  80. var elements_resp_ = await axios.get('http://localhost:8000/elements/', { withCredentials: true });
  81. var elements_ = elements_resp_.data;
  82. console.log(ppage);
  83.  
  84. page_code = babel.transform(ppage.code, { presets: babelpres });
  85.  
  86. // let jsx_ucode = ``
  87.  
  88. // let code = `
  89. // let postdata = () => {
  90. // return (
  91. // <div>
  92. // // ${post_ccode}
  93. // </div>
  94. // )
  95. // }
  96. // `
  97.  
  98. // jsx_ucode = jsx_ucode + code
  99.  
  100. // elements_.forEach(element => {
  101. // let elcode = `
  102. // let elem_${element.id} = () => {
  103. // el = {
  104. // id: "${element.id}",
  105. // name: "${element.name}",
  106. // rpl: ${element.rpl},
  107. // raw: ${element.raw},
  108. // owner: "${element.ownerid}"
  109. // }
  110. // return (
  111. // <div>
  112. // ${element.code}
  113. // </div>
  114. // )
  115. // }
  116. // `
  117. // jsx_ucode = jsx_ucode + elcode
  118. // });
  119.  
  120.  
  121. js_ucode = babel.transform('let one = 1', { presets: babelpres }).code;
  122.  
  123. console.log(jsx_ucode);
  124.  
  125. res.end();
  126. });
  127.  
  128. app.listen(servPort, function () {
  129. console.log('Page Server Listening On Port ' + servPort + "!");
  130. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement