feature: serverus modularly serves up a directory as an HTTP server
This commit is contained in:
commit
58139b078d
20 changed files with 1449 additions and 0 deletions
48
serverus.ts
Normal file
48
serverus.ts
Normal file
|
@ -0,0 +1,48 @@
|
|||
import { parseArgs } from '@std/cli/parse-args';
|
||||
import { SERVER } from './server.ts';
|
||||
import * as path from '@std/path';
|
||||
|
||||
const settings = parseArgs(Deno.args, {
|
||||
boolean: ['help', 'logs', 'version'],
|
||||
string: ['hostname', 'port', 'root'],
|
||||
negatable: ['logs'],
|
||||
alias: {
|
||||
help: 'h',
|
||||
port: 'p',
|
||||
root: 'r',
|
||||
version: 'v'
|
||||
},
|
||||
default: {
|
||||
hostname: 'localhost',
|
||||
logs: true,
|
||||
port: '8000',
|
||||
root: Deno.env.get('SERVERUS_ROOT') ?? './'
|
||||
}
|
||||
});
|
||||
|
||||
if (settings.help) {
|
||||
console.log(
|
||||
`Usage: serverus [--h(elp)] [--v(ersion)] [--no-logs] [--r(oot) ./www]
|
||||
|
||||
Options:
|
||||
-h, --help Show this help message
|
||||
--hostname Set the hostname/ip to bind to, default: localhost
|
||||
--no-logs Disable logging
|
||||
-p, --port Set the port to bind to, default: 8000
|
||||
-r, --root Set the root directory to serve, default: './'
|
||||
-v, --version Show the version number
|
||||
`
|
||||
);
|
||||
Deno.exit(0);
|
||||
}
|
||||
|
||||
const resolved_root: string = path.resolve(settings.root);
|
||||
Deno.chdir(resolved_root);
|
||||
|
||||
const server = new SERVER({
|
||||
hostname: settings.hostname,
|
||||
port: typeof settings.port == 'string' ? parseInt(settings.port) : undefined,
|
||||
logging: settings.logs
|
||||
});
|
||||
|
||||
await server.start();
|
Loading…
Add table
Add a link
Reference in a new issue