mayo / metalsmith-serve Goto Github PK
View Code? Open in Web Editor NEWA metalsmith plugin to serve the build directory. – This plugin is up for adoption.
A metalsmith plugin to serve the build directory. – This plugin is up for adoption.
This may be totally silly, but I keep trying to serve to port 80 and when I do the app quits right away. I'm new to serving publicly, so this might just be me.
Thanks,
Ben
Hi,
if I try to install metalsmith-serve with 'npm install metalsmith-serve* I get the error in the title.
I had to use the following command to install it:
npm install git+https://github.com/mayo/metalsmith-serve.git
Best regards,
Daniel
The readme recommends usage with metalsmith-watch, however when the watcher changes a file then metalsmith-serve tries to spawn a new server and crashes. The error output is this:
[metalsmith-serve] serving /projects/test/build at http://localhost:8082
Started watching **/*
articles/hello-world.md was changed
[metalsmith-serve] serving /projects/test/build at http://localhost:8082
events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at errnoException (net.js:904:11)
at Server._listen2 (net.js:1042:14)
at listen (net.js:1064:10)
at net.js:1146:9
at asyncCallback (dns.js:68:16)
at Object.onanswer [as oncomplete] (dns.js:121:9)
And my configuration looks like this (the rest has been stripped for brevity):
var Metalsmith = require('metalsmith'),
serve = require('metalsmith-serve'),
watch = require('metalsmith-watch');
Metalsmith(__dirname)
.use(serve({
port: 8082,
verbose: true
}))
.use(watch())
// ...
.build(function(err) {
if (err) { throw err; }
});
I think this might be a bug in the code but I'm unsure of how to fix it. Any suggestions? 😄
Specifically, the document_root is not passed in on line 19 in the npm version
running metalsmith-serve standalone with metalsmith
var Metalsmith = require('metalsmith'),
serve = require('metalsmith-serve');
Metalsmith(__dirname)
.use(serve())
.build(function(err) {
if (err) throw err;
})
technically it 'serves' (the task runs) but browser returns 'not found'
maybe user error but seems pretty simple, not sure why it wouldn't work.
Is there any way to write logs from metalsmith-serve to files? I have used the verbose option but haven't found a way to write the logs to files.
There is currently no way to set host as null, as the default is localhost, and if you pass in null, it is overwritten by the default. Not assigning a host is useful if I want to do some quick internal testing on other devices, e.g. to have my iPhone hit my mac ip address to look at the site, but since the http server is only listening on localhost, it wont work, unless I get the IP address of my mac, and update the options to have it.
If you changed defaults.host = null, then it defaults to null, but still allows someone to set localhost if they desire.
I was trying to use the stock serve configuration:
...
.use(serve())
...
This basic config throws the following error:
/Users/marcelo/development/metalsmith-v2/node_modules/metalsmith-serve/lib/index.js:101
if (!options[key]) {
^
TypeError: Cannot read property 'cache' of undefined
at /Users/marcelo/development/metalsmith-v2/node_modules/metalsmith-serve/lib/index.js:101:17
at Array.forEach (native)
at plugin (/Users/marcelo/development/metalsmith-v2/node_modules/metalsmith-serve/lib/index.js:100:25)
at Object.<anonymous> (/Users/marcelo/development/metalsmith-v2/metalsmith.js:37:8)
at Module._compile (module.js:398:26)
at Object.Module._extensions..js (module.js:405:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:430:10)
at startup (node.js:141:18)
at node.js:980:3
I'm on node v5.3.0.
I'm hoping this isn't just user error?
metalsmith-serve should be able to read mime-types from file meta and set the mimetype on the response header.
I was playing around with it here you can set the mimetype, but node-static just overwrites it. There's a closed issue about this on node-static. There's a number of other (open) issues on node-static re mimetypes. I don't think it's going to be resolved any time soon.
Take a look at this post on the slack channel, it kind of explains the context of what I'm trying to do.
So any ideas on how this might be fixed upstream ? I know it would be impractical to change dependencies for such a small feature, but there are other static servers that could easily resolve this.
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.