Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- var querystring = require('querystring');
- var http = require('http');
- var app = require('express')();
- var axios = require('axios');
- var babel = require('@babel/core');
- var APIservPort = 8000;
- var APIservHost = '127.0.0.1';
- var servPort = 8002;
- var babelpres = ["@babel/preset-env", "@babel/preset-react", "es2016"];
- 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';
- function apiRequest(props, r) {
- var _props$path = props.path,
- path = _props$path === undefined ? '/' : _props$path,
- _props$method = props.method,
- method = _props$method === undefined ? 'GET' : _props$method,
- _props$params = props.params,
- params = _props$params === undefined ? {} : _props$params,
- _props$headers = props.headers,
- headers = _props$headers === undefined ? { 'Content-Type': 'application/json' } : _props$headers;
- params = querystring.stringify(params);
- var ret;
- axios({
- method: method,
- url: 'http://' + APIservHost + ':' + APIservPort + '/' + path,
- responseType: 'stream',
- headers: headers,
- params: params
- }).then(r).catch(function (err) {
- console.log(err);
- });
- }
- // app.get("/",function(req,res) {
- // res.send('hi')
- // })
- app.get("/:pageid", async function (req, res) {
- // built-in components
- var response = await axios.get('http://localhost:8000/page/' + req.params.pageid, { withCredentials: true });
- _page_jsx_code = response.data.code;
- var elements = await axios.get('http://localhost:8000/elements/', { withCredentials: true }).data;
- //page_code = babel.transform(_jsx_code,{ presets: babelpres})
- var jsx_ucode = "";
- res.end();
- });
- app.get("/p/:postid", async function (req, res) {
- // built-in components
- var post_resp_ = await axios.get('http://localhost:8000/element/' + req.params.postid, { withCredentials: true });
- var post = post_resp_.data;
- if (!post.post) {
- res.send('post not found');
- res.end();
- }
- var post_ccode = post.code;
- var ppage_resp_ = await axios.get('http://localhost:8000/page/__posth');
- var ppage = ppage_resp_.data;
- var elements_resp_ = await axios.get('http://localhost:8000/elements/', { withCredentials: true });
- var elements_ = elements_resp_.data;
- console.log(ppage);
- page_code = babel.transform(ppage.code, { presets: babelpres });
- // let jsx_ucode = ``
- // let code = `
- // let postdata = () => {
- // return (
- // <div>
- // // ${post_ccode}
- // </div>
- // )
- // }
- // `
- // jsx_ucode = jsx_ucode + code
- // elements_.forEach(element => {
- // let elcode = `
- // let elem_${element.id} = () => {
- // el = {
- // id: "${element.id}",
- // name: "${element.name}",
- // rpl: ${element.rpl},
- // raw: ${element.raw},
- // owner: "${element.ownerid}"
- // }
- // return (
- // <div>
- // ${element.code}
- // </div>
- // )
- // }
- // `
- // jsx_ucode = jsx_ucode + elcode
- // });
- js_ucode = babel.transform('let one = 1', { presets: babelpres }).code;
- console.log(jsx_ucode);
- res.end();
- });
- app.listen(servPort, function () {
- console.log('Page Server Listening On Port ' + servPort + "!");
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement