-
Notifications
You must be signed in to change notification settings - Fork 0
Using WebCore
Martin Góč edited this page Jan 3, 2025
·
4 revisions
You can create and start webserver by using:
const mywebserver = new WebServer({ port: 3000, }); mywebserver.startServer()
Static contexts can be registered using:
mywebserver.createContext(new MyContextClass("/mycontext"))
Dynamic contexts using:
mywebserver.createContext(new MyContextClass("/mycontext/:id"))
Contexts can be registered both before and after starting webserver. Example context file:
export default class MyContextClass extends WebContext {
constructor(url: string){
super(url);
}
handle(request: IncomingMessage, response: ServerResponse, params?: Record<string, string>) {
response.writeHead(HttpCode.OK);
response.end()
}
}
params variable is only available with dynamic routing.