Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A simple server to serve mock data for the Room Manager app (https://github.com/bborgesr/room-manager)
const express = require("express");
const cors = require("cors");
const reservations = [
{
reservaID: 1,
usuarioID: 1,
salaID: 1,
data: "2020-01-31",
horaEntrada: "2020-01-31T10:00:00",
horaSaida: "2020-01-31T11:00:00"
},
{
reservaID: 2,
usuarioID: 1,
salaID: 1,
data: "2020-01-31",
horaEntrada: "2020-01-31T10:00:00",
horaSaida: "2020-01-31T11:00:00"
},
{
reservaID: 3,
usuarioID: 2,
salaID: 1,
data: "2020-01-31",
horaEntrada: "2020-01-31T10:00:00",
horaSaida: "2020-01-31T11:00:00"
},
{
reservaID: 4,
usuarioID: 2,
salaID: 1,
data: "2020-01-31",
horaEntrada: "2020-01-31T10:00:00",
horaSaida: "2020-01-31T11:00:00"
},
{
reservaID: 5,
usuarioID: 1,
salaID: 1,
data: "2020-01-31",
horaEntrada: "2020-01-31T10:00:00",
horaSaida: "2020-01-31T11:00:00"
},
{
reservaID: 6,
usuarioID: 1,
salaID: 2,
data: "2020-01-31",
horaEntrada: "2020-01-31T10:00:00",
horaSaida: "2020-01-31T11:00:00"
},
{
reservaID: 7,
usuarioID: 1,
salaID: 2,
data: "2020-01-31",
horaEntrada: "2020-01-31T10:00:00",
horaSaida: "2020-01-31T11:00:00"
},
{
reservaID: 8,
usuarioID: 1,
salaID: 3,
data: "2020-01-31",
horaEntrada: "2020-01-31T10:00:00",
horaSaida: "2020-01-31T11:00:00"
}
];
const users = [
{
usuarioID: 1,
sobrenome: "Borges",
primeironome: "Barbara",
login: "bborges"
},
{
usuarioID: 2,
sobrenome: "Machado",
primeironome: "Sergio",
login: "smachado"
},
{
usuarioID: 3,
sobrenome: "Curioso",
primeironome: "Catarina",
login: "ccurioso"
},
{
usuarioID: 4,
sobrenome: "Blaya",
primeironome: "Felipe",
login: "fblaya"
},
{
usuarioID: 5,
sobrenome: "Mattos",
primeironome: "Marcelo",
login: "mmattos"
}
];
const rooms = [
{
salaID: 1,
nome: "Porto"
},
{
salaID: 2,
nome: "Vila Nova de Gaia"
},
{
salaID: 3,
nome: "Matosinhos"
}
];
const server = express();
server.use(cors());
server.get("/reservations", (req, res) => {
res.send(JSON.stringify(reservations));
});
server.get("/users", (req, res) => {
res.send(JSON.stringify(users));
});
server.get("/rooms", (req, res) => {
res.send(JSON.stringify(rooms));
});
server.listen(1337);
@bborgesr

This comment has been minimized.

Copy link
Owner Author

@bborgesr bborgesr commented Feb 4, 2020

A simple server. To replicate, create a file index.js with the code above and in the terminal, type:

yarn
yarn add express
yarn add cors
node index.js # to run the server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment