-
-
Notifications
You must be signed in to change notification settings - Fork 580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Server side conversions #716
Conversation
This reverts commit f502723.
Server side conversions
dist/server/BackwardCompat.js
Outdated
* used for backward compat | ||
* also the static files are taken from //{{host}}/static/Y-Z | ||
*/ | ||
const LATEST_VERSION = require(Path.resolve(__dirname, '../../package.json')).version.split('.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, if you start the server with NPM, it sets an env variable for you : process.env.npm_package_version
// then download all assets | ||
// FIXME: should use unifile's batch method to avoid conflicts or the "too many clients" error in FTP | ||
//return Promise.all([ | ||
return sequential([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As previously discussed you should do that. But maybe you want to clean that in another PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes as you told me it is better to test if a file exist and by writing and checking the error
But I would rather do that in an other PR because this current solution is the result of many problems with unifile batch and I am not comfortable changing it now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mainly you need to address the package.json problem
dist/server/PublishJob.js
Outdated
assets | ||
.filter(file => !!file) | ||
.map(file => { | ||
if(file.path === 'css/') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops old code sorry
dist/server/PublishRouter.js
Outdated
// publication tasks | ||
router.post('/tasks/:task', bodyParser.json(), (req, res, next) => { | ||
// init the session (shouldn't it be done by express?? | ||
req.session.sessionID = req.session.sessionID || uuid.v4(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it should. Did you encounter a case where the session was not set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I did
I'll remove it and see what happens since we updated express
const express = require('express'); | ||
const fs = require('fs'); | ||
const { JSDOM } = require('jsdom'); | ||
const bodyParser = require('body-parser'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As seen in CE2, you don't need body-parser
since express 4.16.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concerning JSON: CE adds routes that collide with Silex new routes, e.g. /website/github/get/master/
will be caught by CE as a service called "website/github". So I need to put Silex router before CE router, and so the body needs to be explicit
Concerning text: here I need the body parsed as text, and I can't figure out how to access the body parser from express to use bodyParser.text(
Also in the docs, this is still written to require('body-parser') so I lost too much time with this for now
https://expressjs.com/en/4x/api.html#req.body
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
finally I removed it from CE2 since it doesn't need a parser (right?)
and I added it here #718
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the documentation is outdated on this point but the changelog clearly mentioned the new way to parse bodies https://expressjs.com/en/changelog/4x.html
const cloudExplorerRouter = new CloudExplorerRouter(rootUrl); | ||
app.use(new WebsiteRouter(port, rootUrl, cloudExplorerRouter.unifile)); | ||
app.use(new PublishRouter(port, rootUrl, cloudExplorerRouter.unifile)); | ||
app.use(new SslRouter(app)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's arguable, but IMO this file should act as a controller and perform the environment checks (like SSL and such) before using the router.
In that case, the router wouldn't have to worry about the env and the configuration variables should be injected in its constructor.
This will greatly simplify testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
I'll try to refactor
If you could write this in a separate issue that would be great - not a problem otherwise, I'll try
package.json
Outdated
@@ -38,34 +40,33 @@ | |||
"start:electron": "SILEX_ELECTRON=true electron ." | |||
}, | |||
"dependencies": { | |||
"body-parser": "1.13.3", | |||
"bluebird": "*", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that's what you want. Even with a package-lock
this file should be human readable (the lock clearly isn't).
Basically, we talked about express version and it's now very difficult to know which one is used here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i agree but one of the dependencies has a dependency that breaks the production server but works on localhost. I have no idea which and it is really hard to test since I need to deploy every time (and break the server on preprod.silex.me)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok I decided to give it one more chance, I fixed all versions to the latest available and it seems to work on preprod.silex.me
👍
src/js/service/cloud-storage.js
Outdated
// }); | ||
const oReq = new XMLHttpRequest(); | ||
oReq.onload = function(event) { | ||
if(oReq.status === 200) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happened to your indentation? (╯°□°)╯︵ ┻━┻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
Thanks, great review, I'll fix all this |
Do you think that everything is fine now?
Only the refactoring and the test of existing files remain |
Yep, it's good to go! |
Let's do it! |
Deployment in progress |
Silex is back up |
When Silex saves / opens / publishes a website, it parses the website's DOM to find URLs and make them absolute (when opening) or relative (when saving) or relative to the published version
This PR takes all these operations on the server side, taking advantage of nodejs parsing libraries, and making it possible to parse the DOM without loading any external images or scripts or styles or iframes, and in a cross browser consistent way
This is way cleaner (no more regexp to find the URLs for example), more efficient on the client side, less efficient on the server side, and it fixes long time bugs like #624
Backward compatibility is dropped for this release because I did not manage to port it from client side to server side, but this version is 100% compatible with the one currently on master. So now when you try to open an older website, Silex sends you to https://old.silex.me/ which has the version currently on master. There you can open your website and save it with the version which still has BC on the client side. Then come back to editor.silex.me and you will be able to open it. A BC system is already ready on this PR but it is waiting for the next version to be used.