feature: add SERVERUS_TYPESCRIPT_IMPORT_LOGGING
environment variable
feature(wip): reload on changes
This commit is contained in:
parent
62eba8612b
commit
26125f4f11
5 changed files with 18 additions and 7 deletions
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@andyburke/serverus",
|
||||
"description": "A flexible HTTP server for mixed content. Throw static files, markdown, Typescript and (hopefully, eventually) more into a directory and serverus can serve it up a bit more like old-school CGI.",
|
||||
"version": "0.1.0",
|
||||
"version": "0.2.0",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
".": "./serverus.ts",
|
||||
|
|
|
@ -74,6 +74,11 @@ export default async function handle_typescript(request: Request): Promise<Respo
|
|||
const module: ROUTE_HANDLER = await import(import_path) as ROUTE_HANDLER;
|
||||
|
||||
const pattern = new URLPattern({ pathname: route_path });
|
||||
|
||||
if (Deno.env.get('SERVERUS_TYPESCRIPT_IMPORT_LOGGING')) {
|
||||
console.log(`imported: ${import_path}`);
|
||||
}
|
||||
|
||||
routes.set(pattern, module);
|
||||
} catch (error) {
|
||||
console.error(`Error mounting module ${import_path} at ${route_path}\n\n${error}\n`);
|
||||
|
|
|
@ -31,6 +31,7 @@ export type SERVER_OPTIONS = {
|
|||
hostname?: string;
|
||||
port?: number;
|
||||
logging?: boolean | LOGGER;
|
||||
watch?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -176,6 +177,9 @@ export class SERVER {
|
|||
Deno.addSignalListener('SIGTERM', this.shutdown_binding);
|
||||
Deno.addSignalListener('SIGINT', this.shutdown_binding);
|
||||
|
||||
if (this.options.watch) {
|
||||
Deno.watchFs;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
13
serverus.ts
13
serverus.ts
|
@ -8,31 +8,34 @@ import { SERVER } from './server.ts';
|
|||
import * as path from '@std/path';
|
||||
|
||||
const settings = parseArgs(Deno.args, {
|
||||
boolean: ['help', 'logs', 'version'],
|
||||
boolean: ['help', 'logs', 'version', 'watch'],
|
||||
string: ['hostname', 'port', 'root'],
|
||||
negatable: ['logs'],
|
||||
negatable: ['logs', 'watch'],
|
||||
alias: {
|
||||
help: 'h',
|
||||
port: 'p',
|
||||
root: 'r',
|
||||
version: 'v'
|
||||
version: 'v',
|
||||
watch: 'w'
|
||||
},
|
||||
default: {
|
||||
hostname: 'localhost',
|
||||
logs: true,
|
||||
port: '8000',
|
||||
root: Deno.env.get('SERVERUS_ROOT') ?? './'
|
||||
root: Deno.env.get('SERVERUS_ROOT') ?? './',
|
||||
watch: true
|
||||
}
|
||||
});
|
||||
|
||||
if (settings.help) {
|
||||
console.log(
|
||||
`Usage: serverus [--h(elp)] [--v(ersion)] [--no-logs] [--r(oot) ./www]
|
||||
`Usage: serverus [--h(elp)] [--v(ersion)] [--no-logs] [--no-watch] [--r(oot) ./www]
|
||||
|
||||
Options:
|
||||
-h, --help Show this help message
|
||||
--hostname Set the hostname/ip to bind to, default: localhost
|
||||
--no-logs Disable logging
|
||||
--no-watch Disable watch/reloading for certain types of file changes (handlers, typescript)
|
||||
-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
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import * as asserts from '@std/assert';
|
||||
import { EPHEMERAL_SERVER, get_ephemeral_listen_server } from './helpers.ts';
|
||||
import * as path from '@std/path';
|
||||
|
||||
Deno.test({
|
||||
name: 'override the default handlers',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue