• B8_315146
  • 19.9KB
  • zip
  • 0
  • VIP专享
  • 0
  • 2022-06-11 22:10
试剂同构 试剂同构应用的示例 这是一个示例应用程序,旨在演示在服务器和客户端上都运行的试剂。 它仅用作概念证明。 这绝对不是生产等级。 去做 实在太多了 减少javascript引导代码server.js 展开示例以显示服务器和客户端请求 更清楚地描述服务器和客户端代码 允许应用在生产/调试模式之间切换 先决条件 节点必须已经安装 设置 下载节点模块,关闭nodejs垫片,react库和其他工件。 infra/ 启动服务器 现在,您需要在两个shell中执行以下操作。 外壳#1 infra/lein cljsbuild auto dev node 外壳#2 infra/ 启用了以下URL: 环境变量 名称 描述 默认 节点 节点或nodemon的位置 节点 文档根 静态内容首页; 必须包含cljs-> js代码 目标/开发 概念 我已尝试过尽
# reagent-isomorphic An example of a reagent isomorphic application This is a sample application intended to demonstrate reagent running on both the server and client side. It is intended only as a proof of concept. This is definitely not production grade. ## To Do * Really too many to count * Reduce the javascript bootstrap code, server.js * Expand examples to show both server and client side requests * More clearly delineate server and client side code * Allow app to switch between production/debug mode ## Prerequisite * node must already be installed ## Setup Download the node modules, closure nodejs shim, react library and other artifacts. ``` infra/ ``` ## Starting the server For now, you'll want to perform the following operations in two shells. Shell #1 ``` infra/lein cljsbuild auto dev node ``` Shell #2 ``` infra/ ``` The following URLs are enabled: * [http://localhost:3000/home](http://localhost:3000/home) * [http://localhost:3000/weather/london](http://localhost:3000/weather/london) ## Environment Variables | Name | Description | Default | | :--- | :--- | :--- | | NODE | location of either node or nodemon | node | | DOCROOT | static content home; must include cljs->js code | target/dev | ## Concepts As much as possible, I've tried to minimize the need for ```serverSide?``` and ```clientSide?``` checks within user code. Challenges encountered: * Using single atom instance to represent state works client side, but doesn't work server side. The global state atom needs to be instanced per request. * Ideally, routes should only be defined once and work both server and client side. Server side, because the state is instanced, there needs to be some way to pass the state along through the route. * I hoped that cljs-ajax could be used both server and client side, but alas, without some additional shimming this isn't the case. Consequently, restler is used server side and cljs-ajax is used client side with a facade to hide the differences from the app. * When a page is first rendered that calls an API, both the server side and client side will attempt to execute the query unless additional logic is added. * More to come ... ## Components * express - web server (server-side) * restler - rest client (server-side) * cljs-ajax - rest client (client-side) * st - file server (server-side) * secretary - provides routing (server-side, client-side) * pushy - handles push state (client-side) ## License Copyright © 2015 Matt Ho Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.