webserv v2.0.0-next.1588223411940
Webserv
Why use webserv?
Webserv's aim is to have a fast, simple way to provide a backend to your projects. We want to enable developers to start working on their experience immediately. Webserv is not, nor will ever be a production-ready server (for that we recommend Nestjs). Instead it is a quick and easy way to start serving your app with zero thought or investment.
Serve a folder right now without installing anything using npx.
npx webservWebserv comes with standard server patterns. Start a proxy, CRUD server, upload, or log connections from the command-line. Have a more complex use case? webserv supports JSON configs and has a fully-typed programmatic API so you will never be stuck.
Want to learn more? Read our documentation.
Interested? Start experimenting now on Glitch
Command Line
Webserv allows you to quickly start a fully fledged development server from the command line without editing a single file.
Start a https server with self-signed certificate like this:
webserv -m https -t file ./_dist -p 9999Command-line Options
-m, --mode { http | https }
Create a http or https server (defaults to http)
webserv -m https-l, --log
Log all requests to the console
webserv -l-p, --port
Set the port to use (defaults to 8888)
webserv -p 8000-t crud
Start a basic CRUD server
webserv -t crudThis server keeps records in an internal store.
- GET
/will list all of the records - POST
/with a json object in the body with anidto add a record - PUT
/with a json object in the body to update a record - GET
/id/:idto view a single record - DELETE
/id/:idto delete a record
-t file {directory}
Serve the directory.
This is the default server type. If the directory is omitted the current directory will be served.
webserv -t file ./dist-t log
Create a log server that logs all request to the console and returns 200.
webserv -t log-t proxy {target}
Create a proxy server.
webserv -t proxy http://devpaul.com-t upload {directory}
Create an upload server.
directory is the location where uploaded files will be stored
webserv -t upload ./files- GET
/provides an interface to upload files - POST
/uploads the file(s) - GET
/listlists files that have been uploaded
webserv configuration
Webserv supports more complex usage through config files. When a file named webserv.json is present or when webserv is launched using the -c <configPath> option, webserv will launch using the provided configuration.
The available configurations match the server types (available with the -t option): crud, file, log, proxy, and upload.
The configuration json is used to specify services. Example webserv.json file:
{
"services": [
{
"name": "file",
"paths": {
"/src/*": "./dist",
"/aframe/*": "./node_modules/aframe",
"/node_modules/*": "./node_modules",
"*": "./src"
}
},
{
"name": "upload",
"route": "/upload/*",
"directory": "./uploadDirectory"
},
{
"name": "crud",
"route": "/users/*",
"data": {
"1": {
"id": 1,
"name": "Paul"
}
}
}
]
}All service configurations include a name that refers to the service to be loaded and configuration options. Configuration options may be found on the type definitions in src/config/services.
Programmatic API
For users that may need to create their own services or have complex use cases that are not served the configuration, webserv offers a fully-typed programmatic API. See examples/hello and src/webserv/core/routes for example usage.
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago