bunsvr / utils Goto Github PK
View Code? Open in Web Editor NEWUtilities for parsing and handling requests
Home Page: https://stricjs.netlify.app
Utilities for parsing and handling requests
Home Page: https://stricjs.netlify.app
import { Router } from "@stricjs/router";
import { dir } from "@stricjs/utils";
export default new Router().all("/public/*", dir("./public"));
Display's Bun's standard "Welcome to Bun!" page. No error in console either.
When doing this:
import { response} from '@stricjs/utils';
const badReq = response('Bad request', { status: 400 });
I get the following error:
SyntaxError: Unexpected identifier 'request'. Expected ')' to end an argument list.
at /home/rob/bun6/node_modules/@stricjs/utils/index.js:3:678
Looks like there may be an issue in that module?
The SSE documentation is extremely sparse and difficult to understand how to apply this functionality (I'm familiar with Fastify's SSE interface however, so I know how SSE can be used).
One thing I'd need to be able to do is to identify/recognise the individual connected clients - in Fastify that's done through req.id. Does Stric provide anything similar?
Also could you expand on how to use req.controller? Some simple examples would help
I was following the quick start at https://bun.sh/guides/ecosystem/stric and encountered the following error:
SyntaxError: Export named 'dir' not found in module '/......./node_modules/@stricjs/utils/index.js'.
changing the dependencies in package.json:
"@stricjs/utils": "2.0.7"
bun i
find node_modules/@stricjs/utils/types | grep stream
==> nothing found"@stricjs/utils": "2.0.6"
bun i
find node_modules/@stricjs/utils/types | grep stream
==> nothing found"@stricjs/utils": "2.0.5"
bun i
find node_modules/@stricjs/utils/types | grep stream
==> 🎉 node_modules/@stricjs/utils/types/stream.d.ts
With "@stricjs/utils": "2.0.5"
there's no such error.
Did I miss something or is it a bug?
I want to be able to serve up static files, but want to be able to detect if an incoming file path doesn't actually exist.
I've noticed that the dir object has been replaced with stream.dir, so I've tried this:
`
import { Router } from '@stricjs/router';
import { stream } from '@stricjs/utils';
let router = new Router({port: 3000});
router.get('/*', stream.dir('./www'));
router.use(404, (req) => {
return Response.json({error: 'Unrecognised request'}, {status: 401});
});
export default router;
`
This will correctly return my index.html file from the www directory, but if I request indexy.html which doesn't exist, I get the response:
Welcome to Bun! To get started, return a Response object.
Is there a way to trap this and return a proper 404 response instead?
Within the handler of a parametric route handler, is there a programmatic way to get the parametric URL path that was matched, eg:
router.get('/token/:token', (req) => {
// req.url returns the actual instance of the url that was sent
// is there a way to get the fact it matched /token/:token,
// other than hard-coding in each handler method logic?
});
Many thanks for any advice/suggestions
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.