Stric
  • Basic
    • Intro
    • Routing
    • Serving files
    • Sending HTML
    • Quick response
    • CORS
    • Server-sent events
    • Clustering
  • Advance
    • How it works?
    • More
Powered by GitBook
On this page
  • Searching
  • Grouping

Was this helpful?

  1. Basic

Serving files

Static file serving

The utilities component @stricjs/utils provides 2 ways to serve static files.

Searching

Use the stream method to create a function to search for files based on the request pathname.

import { stream } from '@stricjs/utils';

// Dynamically search for files in the directory
export default { fetch: stream('public'); }; 

Grouping

Use the group method to create a router group that handle each file as a route.

import { Router } from '@stricjs/router';
import { group } from '@stricjs/utils';

// Register each file handler as a route
export default new Router().plug(group('public'));

This method is way faster than file searching but with drawbacks:

  • Files shouldn't be deleted.

  • More files can't be added after running.

  • High memory usage if you have many files.

Last updated 1 year ago

Was this helpful?