0.5.2 • Published 3 years ago

ucdn-utils v0.5.2

Weekly downloads
13
License
ISC
Repository
github
Last release
3 years ago

µcdn-utils

Build Status Coverage Status

Basic µcdn utilities in order to just serve files pre generated via µcompress.

The only interesting utility to use is likely the serve(path[, cacheTimeout]) one, as the rest is mostly needed for internal purposes in µcdn module or in here.

Please Note

This module assumes all files already have associated headers. If you don't have those headers files, please use ucompress.createHeaders(path) before serving via serve(path[, cacheTimeout]).

Example

The following example will serve every file within any folder in the source directory, automatically optimizing on demand all operations, including the creation of brotli, gzip, or deflate.

import {createServer} from 'http';
import {serve} from 'ucdn-utils';

import umeta from 'umeta';
const {dirName} = umeta(import.meta);

const callback = serve(dirName + '/source', 60000);

createServer(callback).listen(8080);

The callback works with Express too, and similar modules, where all non existent files in the source folder will be ignored, and anything else will execute regularly.

const {join} = require('path');

const express = require('express');
const {serve} = require('ucdn-utils');

const app = express();
app.use(serve(join(__dirname, 'source')));
app.get('/unknown', (req, res) => {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('OK');
});
app.listen(8080);
0.5.2

3 years ago

0.5.1

4 years ago

0.5.0

4 years ago

0.4.13

4 years ago

0.4.11

4 years ago

0.4.12

4 years ago

0.4.9

4 years ago

0.4.10

4 years ago

0.4.8

4 years ago

0.4.7

4 years ago

0.4.6

4 years ago

0.4.5

4 years ago

0.4.4

4 years ago

0.4.3

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.4.2

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.1

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.0

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.1

4 years ago

0.0.0

4 years ago