summaryrefslogtreecommitdiff
path: root/src/web.mjs
blob: c3651a91ff46500714df422bf69bf88014435fd7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import * as u    from "./utils.mjs";
import * as hero from "./hero.mjs";

const listProducts = req => ({ status: 200 });
const getProduct   = req => ({ status: 200, body: "PRODUTO\n" });
const getSocket    = req => ({ status: 200, body: "SOCKET\n"  });


const name = "papo";

const routes = [
	[ "GET", "/api/products",     listProducts ],
	[ "GET", "/api/products/:id", getProduct   ],
	[ "GET", "/api/socket",       getSocket    ],
];

export const app = async (socket, pipe) => {
	const server = hero.buildServer({
		name,
		routes,
		socket,
		pipe,
	});
	await server.start();
	hero.log.info({
		type: "starting-server",
		name,
		socket,
		pipe,
	});
};