async-cdn
An Nginx style CDN for delivering static files in Node.JS asynchronously
Last updated 4 months ago by svnty .
Public-Domain · Original npm · Tarball · package.json
$ cnpm install async-cdn 
SYNC missed versions from official npm registry.

async-cdn

An Nginx style CDN to send static files asynchronously

methods

  • readDir('directoryLocation', directoryTraversalProtection, callback())

  • sendFile('directoryLocation', directoryTraversalProtection, callback())

options

  • directory location: string
    • a file or folder location
  • directory traveral protection: boolean
    • if you want the (end) user to be able to navigate backwards through the filesystem with '../../etc/hosts'
  • callback: function()
    • callback function

example

const express = require('express');
const app = express();
const CDN = require('async-cdn');

app.get('/', (req, res) => {
  CDN.readDir('./', true, (err, data) => {
    if (err) return res.json(err);
    res.json(data);
  });
});

app.get('/:folderOrFile', (req, res) => {
  if (req.params.folderOrFile.includes('.')) {
    req.params.folderOrFile = `./${req.params.folderOrFile}`;
    CDN.sendFile(req.params.folderOrFile, true, (err, data) => {
      if (err) return res.json(err);
      res.send(data);
    });
  } else if (!req.params.folderOrFile.includes('.')) {
    req.params.folderOrFile = `./${req.params.folderOrFile}`;
    CDN.readDir(req.params.folderOrFile, true, (err, data) => {
      if (err) return res.json(err);
      res.send(data);
    });
  }
});

app.listen(3000);

license

Public-Domain

Current Tags

  • 1.0.5                                ...           latest (4 months ago)

6 Versions

  • 1.0.5                                ...           4 months ago
  • 1.0.4                                ...           5 months ago
  • 1.0.3                                ...           5 months ago
  • 1.0.2                                ...           5 months ago
  • 1.0.1                                ...           5 months ago
  • 1.0.0                                ...           5 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 8
Last Day 0
Last Week 1
Last Month 6
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |