-
Notifications
You must be signed in to change notification settings - Fork 47
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
Separate server and app initialization into two parts (optional) #67
Comments
@peterwillis you mentioned in #56 that you would be interested in writing a PR for this. Are you still interested in writing a PR for this I think this would be a great idea? Can we do? For routing: |
Yes I think I can something submitted today or tomorrow |
reload has a fork that has middleware definition support. See for yourself : https://www.npmjs.com/package/ack-reload#middlware |
If I needed it to work that way, I could just use the venerable webpack-dev-server. The way that fork works is hijacking the way static content is served which won't work for my middleware chain. Using this package means you can use the express static middleware. |
I like sassy replies! Most all of mine are sassy too!!! Here, it seems again I have to do the leg work to inspire the people using reload:
app.js const express = require('express');
const reload = require('ack-reload');
const app = express();
// LOTS AND LOTS OF MIDDLEWARE HERE...
// server is not created since in this module.
app.use((err, req, res, next) => {
// final error handler
});
app.use( reload.middleware(app, false) )
module.exports = app; serve.js const app = require('./app');
const http = require('http');
const reload = require('ack-reload');
// we actually have http and https switched on configuration, but this example is for brevity
const server = http.createServer(app);
// at this point we have server and app, but the middleware chain setup is completed so we can't add reload.
const pathToWwwFiles = require('path').join(__dirname,'www')
reload.reloadSocketByHttp(pathToWwwFiles, http)
server.listen(8888, () => { console.log('started!') }); Let me know if this works for you. Otherwise make another sassy reply and I'll provide code for you to sit and spin on ;) |
Hey, smart guy, my dumb ass came up with another simplified approach. app.js (untouched - needs no changes) const express = require('express');
const app = express();
// LOTS AND LOTS OF MIDDLEWARE HERE...
// server is not created since in this module.
app.use((err, req, res, next) => {
// final error handler
});
module.exports = app; serve.js const app = require('./app');
const http = require('http');
const reload = require('ack-reload');
//tell ack-reload folder to put watch on
const pathToWwwFiles = require('path').join(__dirname,'www');
// we actually have http and https switched on configuration, but this example is for brevity
const server = http.createServer(function(req,res){
if( reload.isRequestForReload(req) ){
midware(req, res)//request is html OR reload.js file
}else{
app(req, res)
}
});
//watch files, create websocket and return request processing function
const midware = reload.middleware(pathToWwwFiles, server)
// at this point we have server and app, but the middleware chain setup is completed so we can't add reload.
server.listen(8888, () => { console.log('started!') });
|
Sorry I wasn't intending to be smart or sassy - sorry if it came across that way. That doesn't solve the problem at all. You are still delegating the handling of static content to your middleware. If you want to have a conversation about it, perhaps do it on your repos issues not here? |
Sass and read worthy is my intent. I like to create buzz to gain and keep interest. Just letting you know so nothing is taken to heart on either end... Hey good luck solving your issue. I created a new function of const server = http.createServer(function(req,res){
if( reload.isRequestForReload(req) ){
midware(req, res)//request is html OR reload.js file
}else{
app(req, res)
}
}); This new method ensures reload middleware only gets involved when it should and not delegate ALL request. Please review and reply as I think this is your fix. |
It does not - I don't know how I can be clearer about this. Please use your own repository for issues about it. |
Heard loud and extra clear. Intent is absolutely not to harass. Farewell |
Closes by #118 |
Opening a new issue for this idea. This conversation originally started on #56. Relevant comment below.
@peterwillis
The text was updated successfully, but these errors were encountered: