Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@api.global/typedserver
Advanced tools
A TypeScript-based project for easy serving of static files with support for live reloading, compression, and typed requests.
# @api.global/typedserver
Easy serving of static files
## Install
To install @api.global/typedserver, run the following command in your terminal:
```bash
npm install @api.global/typedserver --save
This will add @api.global/typedserver
to your project's dependencies.
@api.global/typedserver
is designed to make serving static files and handling web requests in a TypeScript environment easy and efficient. It leverages Express under the hood, providing a powerful API for web server creation with additional utilities for live reloading, typed requests/responses, and more, embracing TypeScript's static typing advantages.
The following example demonstrates how to set up a basic web server serving files from a directory.
import { TypedServer } from '@api.global/typedserver';
const serverOptions = {
port: 8080, // Port to listen on
serveDir: 'public', // Directory to serve static files from
watch: true, // Enable live reloading of changes
injectReload: true, // Inject live reload script into served HTML files
cors: true // Enable CORS
};
const typedServer = new TypedServer(serverOptions);
async function startServer() {
await typedServer.start();
console.log(`Server is running on http://localhost:${serverOptions.port}`);
}
startServer().catch(console.error);
In the example above, TypedServer
is instantiated with an IServerOptions
object specifying options like the port to listen on (8080
), the directory containing static files to serve (public
), and live reload features. Calling start()
on the typedServer
instance initiates the server.
TypedServer
supports typed requests and responses, making API development more robust and maintainable. Define your request and response types, and use them to type-check incoming requests and their responses.
First, define the types:
// Define a request type
interface MyCustomRequest {
userId: string;
}
// Define a response type
interface MyCustomResponse {
userName: string;
}
Next, set up a route to handle requests using these types:
import { TypedRouter, TypedHandler } from '@api.global/typedrequest';
// Instantiate a TypedRouter
const typedRouter = new TypedRouter();
// Register a route with request and response types
typedRouter.addTypedHandler<MyCustomRequest, MyCustomResponse>(
new TypedHandler('getUser', async (requestData) => {
// Implement your logic here. For example, fetch user data from a database.
const userData = { userName: 'John Doe' }; // Dummy implementation
return { response: userData };
})
);
// Bind the typed router to the server
typedServer.useTypedRouter(typedRouter);
// Now, the route is set up to handle requests with type checking
This example shows defining types for requests and responses, creating a TypedRouter
, and adding a route with typed handling. This feature brings the benefits of TypeScript's static type checking to server-side logic, improving the development experience.
To enable SSL/TLS, configure the TypedServer
with the SSL options, including the paths to your SSL certificate and key files:
const serverOptions = {
port: 443,
serveDir: 'public',
watch: true,
injectReload: true,
cors: true,
privateKey: fs.readFileSync('path/to/ssl/private.key'),
publicKey: fs.readFileSync('path/to/ssl/certificate.crt')
};
const typedServer = new TypedServer(serverOptions);
startServer().catch(console.error);
Replace 'path/to/ssl/private.key'
and 'path/to/ssl/certificate.crt'
with the actual paths to your SSL key and certificate files. This setup ensures that your server communicates over HTTPS, encrypting the data transmitted between the client and the server.
@api.global/typedserver
offers a streamlined way to set up a web server with TypeScript, featuring static file serving, live reloading, typed request/response handling, and SSL support. This guide covers the basic usage, but TypedServer
is highly configurable, catering to various hosting and development needs.
For a deeper dive into the API and more advanced configurations, refer to the official documentation and type definitions included in the package.
## License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
### Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
FAQs
A TypeScript-based project for easy serving of static files with support for live reloading, compression, and typed requests.
We found that @api.global/typedserver demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.