Files
  • index.js
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
var http = require('http');

var operators = [
	{ name: 'DEF', code: 1, category: 'Celphone', price: 1 },
	{ name: 'ABC', code: 2, category: 'Celphone', price: 3 },
	{ name: 'XYZ', code: 3, category: 'Celphone', price: 2 },
];

var contacts = [
	{ id: 1, name: 'Carol', phone: '9839-7231', data: new Date(), operator: operators[0]},
	{ id: 2, name: 'Maria', phone: '9111-2477', data: new Date(), operator: operators[1]},
	{ id: 3, name: 'André', phone: '9009-3223', data: new Date(), operator: operators[2]},
];

http.createServer(function (req, res) {
	res.setHeader('Access-Control-Allow-Origin', '*');
	if (req.url === '/operators') 
		res.write(JSON.stringify(operators));
	if (req.url === '/contacts') 
		res.write(JSON.stringify(contacts));
	res.end();
}).listen(3412);
node v9.7.1 linux/amd64