@pyelias/

backend-demo

Nodejs

No description

fork
loading
Files
  • index.js
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
const http = require("http");
const {URL} = require("url");

const server = http.createServer((req, res) => {
	let url = new URL(req.url, "http://dummy"); // placeholder url
	path = url.pathname;
	params = url.searchParams;
	console.log(path, params);
	switch (path) {
		case ("/api-endpoint"):
			res.setHeader("Access-Control-Allow-Origin", "*");
			res.write("hi from the endpoint " + params.get("a") + " " + params.get("c"));
			break;
	}
	res.end();
});
server.listen(8001);
node v10.16.0