yanni4night / node-ssi Goto Github PK
View Code? Open in Web Editor NEWA server side include system
A server side include system
if file contains ''
includeFileReg exec two expression as one
For fix need change
var includeFileReg = /<!--#\s*include\s+(file|virtual)=(['"])([^\r\n\s]+?)\2\s*(.*)-->/;
to
var includeFileReg = /<!--#\s*include\s+(file|virtual)=(['"])([^\r\n\s]+?)\2\s*(.*?)-->/;
Node v6.4.0 - Express v4.13.4 - CentOS 6.8
Hello,
When I try to install node-ssi through npm install node-ssi
I get the following error. Should I make some kind of json file with settings first? If yes, how ?
/home/mynodeproject/www/package.json
└── [email protected]
npm WARN enoent ENOENT: no such file or directory, open /home/mynodeproject/www/package.json
WARN 001 No description
npm WARN 001 No repository field.
npm WARN 001 No README data
npm WARN 001 No license field.
Example: An HTML file has the following three includes:
<!--#include virtual="/includes/header.html" -->
<!--#include virtual="/includes/content.html" -->
<!--#include virtual="/includes/footer.html" -->
In my situation, the first and last include do not exist on my local development environment, however they will be available once pushed to the test / prod. environment. I am only concerned about rendering the second include, content.html.
The problem is that since the first include does not exist, ssi.compileFile (and ssi.compile) throws an error which means the downstream includes are not processed. In my case, I am using ssi.compile().
return ssi.compile(text, function (err, content) {
});
As a workaround, I was thinking I could grab the failed reference from err
, and parse the original input file content to remove the offending reference then pass this back in to ssi.compile / ssi.compileFile until it has fully processed.
Would like to get your thoughts on implementing continuation of processing on error, however.
Not sure if this is a new or existing issue but I am currently trying to migrate from nginx server with support for ssi to a bespoke node/express server.
The current setup has files in different locations. So for example
we might have root set to
../file_path/www-root
ssi components aliased in say:
../another_file_path/components
and say ssi modules in say ../yet_another_path/modules/
I also have say library and theme folders that serve different files depending on the host url.
Therefore I can have brand1.dev/ brand2.dev etc which is referenced in .htaccess, and I can again use node to route the files accordingly. These are generally not .shtml files but again there may be a some .shtml referenced in these locations
So my question is it possible to use node-ssi to support these multiple locations?
p.s. was kind of getting this confused with this repo.:
Support for nginx style Variables e.g
<!--#if expr = "$REQUEST_URI = mode=([a-zA-Z0-9]+)/)/" -->
<!--#set var = "mode" value="$1" -->
<!--#endif -->
<!--#echo var="mode" -->
这里的${QUERY_STRING} 也会被当作url的一部分导致获取地址错误。
According the spec on Wikipedia:
http://en.wikipedia.org/wiki/Server_Side_Includes
It seems wrong in the note of current readme file.
If I'm understanding correctly, the example given in the current README doesn't actually show how to quickly run a server with this.
Can you post simple example code that can be used to simply server pages in a folder?
For example, I'd like to be able to run node index.js
from a directory containing an index.html
file and for that to immediately start a server on localhost:8080
serving that file (and any other linked images, sub-links, SSI includes, etc.) automatically (for developing locally without having to install nginx on a dev machine).
'''
《!--#config timefmt="%Y%m%d%H%M%S" --》
var SERVER_TIME_STR = '';
'''
我这样写的,,大多数ssi都不知道config...你这个是否可以
👍 Just wanted to let you know that I'm excited to see this, and I'm going to try it out because we have a use for it: okTurtles/okturtles.com#15
Thanks! Hope it works! crosses-fingers
When Apache parses SSI statements, it treats =
and ==
as equivalent in conditional expressions, and if a variable is on the left side of the operator, the variable's value remains unchanged after the statement is evaluated.
For example, if variableName
is set to 'someValue'
, then <!--#if expr="$variableName = 'anotherValue'"-->
and <!--#if expr="$variableName == 'anotherValue''"-->
will both evaluate as false
, and variableName
's value will still be someValue
.
In node-ssi, however, using =
with a variable in an #if
statement causes the variable's value to change. The workaround is to use ==
instead, but ideally that shouldn't be necessary.
I created a test here: https://runkit.com/lordpachelbel/runkit-npm-node-ssi — You can click the tiny arrow to the left of the console output to see it rendered as HTML.
The unminified version of the HTML string in that test is this:
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8" />
<title>SSI test page</title>
</head>
<body>
<h1>SSI test page</h1>
<p>Initial <code>#set</code> happens here.</p>
<!--#set var="loginStatus" value="on"-->
<p><code>loginStatus</code>: <code><!--#echo var="loginStatus"--></code></p>
<h2>Using <code>==</code></h2>
<p><code>#if expr="$loginStatus == 1"</code> :<br />
<!--#if expr="$loginStatus == 1"-->
<span style="color: white; background: green;">enabled</span>
<!--#else-->
<span style="color: white; background: red;">disabled</span>
<!--#endif-->
<br />
<code>loginStatus</code>: <code><!--#echo var="loginStatus"--></code></p>
<p><code>#if expr="$loginStatus == '1'"</code> :<br />
<!--#if expr="$loginStatus == '1'"-->
<span style="color: white; background: green;">enabled</span>
<!--#else-->
<span style="color: white; background: red;">disabled</span>
<!--#endif-->
<br />
<code>loginStatus</code>: <code><!--#echo var="loginStatus"--></code></p>
<p><code>#if expr="$loginStatus == 'on'"</code> :<br />
<!--#if expr="$loginStatus == 'on'"-->
<span style="color: white; background: green;">enabled</span>
<!--#else-->
<span style="color: white; background: red;">disabled</span>
<!--#endif-->
<br />
<code>loginStatus</code>: <code><!--#echo var="loginStatus"--></code></p>
<p><code>#if expr="$loginStatus == ''"</code> :<br />
<!--#if expr="$loginStatus == ''"-->
<span style="color: white; background: green;">enabled</span>
<!--#else-->
<span style="color: white; background: red;">disabled</span>
<!--#endif-->
<br />
<code>loginStatus</code>: <code><!--#echo var="loginStatus"--></code></p>
<p><code>#if expr="$loginStatus == 'anything'"</code> :<br />
<!--#if expr="$loginStatus == 'anything'"-->
<span style="color: white; background: green;">enabled</span>
<!--#else-->
<span style="color: white; background: red;">disabled</span>
<!--#endif-->
<br />
<code>loginStatus</code>: <code><!--#echo var="loginStatus"--></code></p>
<h2>Using <code>=</code></h2>
<p><code>#if expr="$loginStatus = 1"</code> :<br />
<!--#if expr="$loginStatus = 1"-->
<span style="color: white; background: green;">enabled</span>
<!--#else-->
<span style="color: white; background: red;">disabled</span>
<!--#endif-->
<br />
<code>loginStatus</code>: <code><!--#echo var="loginStatus"--></code></p>
<p><code>#if expr="$loginStatus = '1'"</code> :<br />
<!--#if expr="$loginStatus = '1'"-->
<span style="color: white; background: green;">enabled</span>
<!--#else-->
<span style="color: white; background: red;">disabled</span>
<!--#endif-->
<br />
<code>loginStatus</code>: <code><!--#echo var="loginStatus"--></code></p>
<p><code>#if expr="$loginStatus = 'on'"</code> :<br />
<!--#if expr="$loginStatus = 'on'"-->
<span style="color: white; background: green;">enabled</span>
<!--#else-->
<span style="color: white; background: red;">disabled</span>
<!--#endif-->
<br />
<code>loginStatus</code>: <code><!--#echo var="loginStatus"--></code></p>
<p><code>#if expr="$loginStatus = ''"</code> :<br />
<!--#if expr="$loginStatus = ''"-->
<span style="color: white; background: green;">enabled</span>
<!--#else-->
<span style="color: white; background: red;">disabled</span>
<!--#endif-->
<br />
<code>loginStatus</code>: <code><!--#echo var="loginStatus"--></code></p>
<p><code>#if expr="$loginStatus = 'anything'"</code> :<br />
<!--#if expr="$loginStatus = 'anything'"-->
<span style="color: white; background: green;">enabled</span>
<!--#else-->
<span style="color: white; background: red;">disabled</span>
<!--#endif-->
<br />
<code>loginStatus</code>: <code><!--#echo var="loginStatus"--></code></p>
</body>
</html>
The top and bottom parts of the test page are supposed to look the same, but the variable's value is changed by the last four #if
statements. Note that the only time the =
works as intended is the first one in the bottom section, and I assume it has something to do with the fact that that conditional is doing a numerical comparison instead of a string comparison.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.