Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "airbnb",
"env": {
"jest": true
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
coverage
lib
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js
node_js:
- "8"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want "stable" or 10 also since that's the current version in development, not important, but it crossed my mind when I saw this :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@philippemiguet I think just lts/* should work which is now node 10 and we should be using only LTS releases for our production services 😄 . If this ends up using language features that only exist in node 10 and we need to polyfill for node 8 or below we can add 8. I think this repo should use pretty standard/stable language features so running the tests against 10 😄

notifications:
email: false
81 changes: 81 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# buffer-js-static-assets

[![Build Status](https://travis-ci.org/bufferapp/buffer-js-static-assets.svg?branch=master)](https://travis-ci.org/bufferapp/buffer-js-static-assets)

## Installation

Install the package

```
npm install @bufferapp/static-assets
```

## Usage

To utilize the `staticUrl` function, you'll need to first initialize the
static assets manager:

```js
const { initStaticAssets } = require('@bufferapp/static-assets')

initStaticAssets()
.then(() => {
// Now that we have loaded the static assets we can serve requests
app.listen(8080, () => console.log('Server started!'))
})
```

Alternatively, you can call the `initStaticAssetsSync` function to perform
a synchronous load of the static assets file which is blocking:

```js
initStaticAssetsSync()
app.listen(8080, () => console.log('Server started!'))
```

Once the library is initialized, using the exported `staticUrl` function:

```js
const { staticUrl } = require('@bufferapp/static-assets')

app.get('/sweet', (req, res) => {
res.render('sweet-template', {
headerImage: staticUrl('img/sweet-header4.png'),
script: staticUrl('js/sweet-bundle.js'),
})
})
```

### Options

We have a few configuration options that can be passed to `initStaticAssets` in
a single object argument (ex. `initStaticAssets({ path: '/static' })`):

* `staticAssetVersionsFilename` - The name of the static asset manifest file.
* `staticAssetDirLocal` - The relative path where static assets are served during local dev. Usually via express-static.
* `staticAssetDirCDN` - This is the directory relative to your working directory where your static assets are saved. This is used to look up static files in the manifest (See manifest section below).

### Static Asset Manifest

The format of the static asset manifest should be the same as default JSON
format that [`buffer-static-upload`](https://github.com/bufferapp/buffer-static-upload)
outputs.

This format is a key-value pair of:

```json
"relative path to local file from working directory": "remote URL for that file"
```

Here's an example:

```json
{
"public/css/style.css": "https://static.buffer.com/my-app/public/css/style.1234567890.css",
"public/img/brand.png": "https://static.buffer.com/my-app/public/img/brand.png"
}
```

## License

MIT
Loading