Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Log content paths to console #167

Merged
merged 9 commits into from
Jun 20, 2018
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,22 @@ instance.
Type: `String|[String]`
Default: `process.cwd()`

The path, or array of paths, from which content will be served.
The path, or array of paths, from which static content will be served.

_Note: By default the files served from `content` paths take precedence
over files generated by webpack._

To instruct the server to give webpack files precedence, use the `add`
option, and call `webpack.middleware()` before `content middleware()`:

```js
add: (app, middleware, options) => {
middleware.webpack();
middleware.content();
};
```

Read more about the add option in [Add-On Features](#add-on-features).

<!-- intentionally out of alphabetic order -->
##### clipboard
Expand Down
18 changes: 18 additions & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { relative } = require('path');
const http = require('http');
const https = require('https');

Expand Down Expand Up @@ -49,6 +50,23 @@ module.exports = (options) => {
},
content: (staticOptions) => {
middleware.content.called = true;

const formattedPaths = options.content
.map((dir) => relative(process.cwd(), dir))
.map((dir) => `/${dir}/`);

if (formattedPaths.length === 1) {
log.info(
chalk`Serving Static Content from: {grey ${formattedPaths[0]}}`
);
} else {
let logMessage = 'Serving Static Content from:\n';
for (const dir of formattedPaths) {
logMessage += chalk` {grey ${dir}}\n`;
}
log.info(logMessage);
}

for (const dir of options.content) {
app.use(serveStatic(dir, staticOptions || {}));
}
Expand Down