async-cdn
An Nginx style CDN for delivering static files in Node.JS asynchronously
Last updated 11 days 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())

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.4                                ...           latest (11 days ago)

5 Versions

  • 1.0.4                                ...           11 days ago
  • 1.0.3                                ...           11 days ago
  • 1.0.2                                ...           17 days ago
  • 1.0.1                                ...           17 days ago
  • 1.0.0                                ...           17 days ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 60
Last Day 0
Last Week 1
Last Month 0
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |