feat: http routes

This commit is contained in:
cha0s 2020-12-06 21:49:29 -06:00
parent e911c2e6fd
commit 20ad1957ae

View File

@ -2,6 +2,7 @@ import {createReadStream} from 'fs';
import {createServer} from 'http';
import {join} from 'path';
import {arrayFlatten} from '@latus/core';
import express from 'express';
import latusMiddleware from './latus';
@ -21,6 +22,8 @@ export const createHttpServer = async (latus) => {
app.use((req, res, next) => {
latus.invokeMiddleware('@latus/http/request', req, res, next);
});
const routes = arrayFlatten(latus.invokeFlat('@latus/http/routes'));
routes.forEach(({method, path, handler}) => app[method](path, handler));
// Serve latus.
app.use(latusMiddleware(latus));
app.use(express.static(join(__dirname, 'client')));