Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Typescript node.js 服务器开发框架
本人英文不好,莫笑。
npm install -g etmx
etmx create [project name]
ETMX is a typescript server framework, base on express framework.
ETMX contains:
1、 Server(use this class to create a server)
2、 Router(use this class to create a router)
3、 RouterManager(use this class to manage routers)
4、 Database(use this class to handle database)
ETMX use a .json file or a object like to configure server, configurations contains:
server ------ server base configurations
port ------ port of web server listen, default is 3000
protocol ------ http or https, default is http
https ------ if https protocol used, configure this field
cert ------ ssl cert
key ------ private key of cert
path ------ this configurations contains used paths of server
cache ------ path of cache directory, default is /temp/etmx
static ------ path of static resources directory(s),
view ------ path of view, if you don't hav views, ignore it
cross ------ is cross-domain, default is false
favicon ------ path of favicon image
websocket ------ use web socket, default is false
log ------ is request log show, default is true
database ------ database configurations
type ------ database type, default is mysql, but now, only mysql can be used
host ------ database host, default is localhost
port ------ database port, this will use default port of database that you set
user ------ database user
password ------ password of database user
db ------ database to use
charset ------ charset of mysql to use, default is utf8
timezone ------ timezone of mysql to use, default is local
use Router class to create a router, example:
import {Router} from 'etmx';
let router = new Router();
router
//set router name
.name('/main')
//hello world
.get('/test', (req, res, next) => {
res.end('Hello world');
})
//mysql query
.get('/user/:number/:name', (req, res, next) => {
// use router.mysql.xxxx to handle mysql
// use easy to create a mysql connection, this method can release connection automatically when connection unused.
router.mysql.easy(async mysql => {
try {
let data = await mysql.query('select * from ??', 'user');
res.json(data);
} catch (e) {
console.log(e);
}
});
});
//must use export default to export a router
export default router;
Now, let's create a server and start it
import {Server, RouterManager} from 'etmx';
import * as path from 'path';
//set path of server configurations
Server.confdir = path.join(__dirname, './');
//set server root file directory
Server.rootdir = __dirname;
//create a server use etmx.json file
let server = new Server('etmx');
//set routers
server.routers = app => {
//create a router manager whit directory of current file
let manager = new RouterManager(__dirname);
//use manager.router = xxxx to add a router
[
'./Main',
].forEach(_r => manager.router = _r);
//manager.routers to get all routers
return manager.routers;
};
//use create method to create a server
server.create();
Etmx provide a easy way to create and manage websocket, to use websocket you should do:
:::notice:if your webserver use https websocket is wss://, if http websocket is ws://
webscket setting like:
{
"server": {
"websocket":true
}
}
websocket handler like:
import {WSHandler, WSManager} from './';
//this is websocket params
interface Props {
uid:string, //give a uid param to mark a user
uname:string, //user name
}
export class HandlerName extends WSHandler<Props> {
onConnect() {
//when a socket connect to server
console.log(this.params.uid);
//send a welcome message
this.send({type:'welcome', message:'Welcome to join this room'});
}
onClose() {
//when a socket closed
//send a user leave message
WSManager.handlers.forEach(handler=>{
if(handler.params.uid == this.params.uid) return;
handler.send({type:'leave', message:`[${this.params.uname}] left this room`})
})
}
onMessage(message) {
//when receive message
//send message to all but myself
WSManager.handlers.forEach(handler=>{
if(handler.params.uid == this.params.uid) return;
handler.send({type:'text', message:message});
})
}
}
the end, in entry file set
server.wsHandler = HandlerName;
FAQs
Typescript nodejs web server framework
The npm package etmx receives a total of 0 weekly downloads. As such, etmx popularity was classified as not popular.
We found that etmx 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.