Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
express-offline
Advanced tools
Readme
Allows an express app be placed into offline mode and automagically serve responses from disk.
npm install --save express-offline
In the example below, the /microdata
route extracts microdata from any website and returns it as a JSON object. So, if we run the example and request localhost:8080/microdata?url=http://mammothworkwear.com/dickies-proban-coverall-p562.htm
it will return a JSON object containing product information:
{
...
{
"id": "14ef1e7a452ceca27c8124b3c26f4b74",
"name": "http://schema.org/Product",
"properties": {
"name": "Dickies Proban Coverall",
"manufacturer": "Dickies",
"brand": "Dickies",
"mpn model": "FR4869",
"image": "http://mammothworkwear.com/dickies-proban-coverall-w385h385q94i6368.jpg",
"description": "If your workplace really cranks up the heat - literally as well as figuratively - then the Dickies Proban Coverall is for you. Constructed from special flame-retardant fabrics to comply with safety standards EN531 and EN470, this boiler suit offers high quality and reliable performance in hazardous areas. If you can expect a tripartite attack from fire, sparks and molten materials all before lunchtime, you'll need this kind of self-extinguishing clothing. Made to limit burn injuries and protect you against extreme heat, the overalls are ideal for those who work in the welding trade. As well as sporting a proban finish, the garment comes with a concealed stud front and cuffs with stud closure. There's also a studded neck closure, to ensure no sections of clothing come unhoused and dangle over flames and suchlike. Constructed from 330g of 100% cotton drill, this one comes with reinforced stress points and a pair of patch pockets at the chest. There are also further pockets in the seat and at the sides. If you can't stand the heat, don't get out of the workplace - get into the Dickies Proban Flame Retardant Overalls.",
"offers": "1 to 445.47"
}
}
...
}
We probably dont want to be hitting the workwear site for every request during development, so we add the express-offline
middleware and run our app with the environment variable OFFLINE=true.
Future requests will now return the contents of ./offline/development/get/microdata.json
.
var express = require('express');
var getMicrodata = require('node-microdata-scraper'); // extract microdata from a website
var app = express(); // create an instance of express
var offline = require('express-offline'); // load express-offline middleware module
// add express-offline middleware to intercept requests (must be added before all other routes)
app.use(offline());
// demo express route to extract microdata from a webpage passed as a query-string
app.get('/microdata', function(req, res) {
var url = req.query.url;
// extract microdata from URL and return to browser
getMicrodata.parseUrl(url, function(err, data) {
var json = JSON.parse(data);
res.json(json);
});
});
app.listen(8080);
By default express-offline will look for an offline folder in the root of your application. Path's are them mapped using the following formula:
./offline/ + NODE_ENV + / + HTTP_METHOD + / + REQUEST_PATH.ACCEPT_HEADER (all in lowercase!)
So the following GET request to your application running in development mode would return ./offline/development/get/microdata.json
GET /microdata?url=http://mammothworkwear.com/dickies-proban-coverall-p562.htm HTTP/1.0
Accept: application/json
The following POST request to your application running in production mode would return ./offline/production/post/microdata.html
POST /microdata HTTP/1.0
Accept: text/html
This project includes a working example. You can run in online mode using:
node ./node-modules/express-offline/example.js
And in offline mode using:
OFFLINE=true node ./node-modules/express-offline/example.js
The following tasks need doing, so please feel free to contribute:
Licensed under ISC License © John Doherty
FAQs
Allows an express app be placed into offline mode and automagically serve responses from disk.
The npm package express-offline receives a total of 62 weekly downloads. As such, express-offline popularity was classified as not popular.
We found that express-offline demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.