Archived
colors ;-;
This commit is contained in:
1 parent
94bbb4e473
commit
a2fc07aa62
2 files changed
+105
-91
No files matched your search
@@ -1,64 +1,64 @@
|
||||
require('dotenv').config();
|
||||
require("dotenv").config();
|
||||
const express = require("express");
|
||||
const cors = require("cors");
|
||||
const app = express();
|
||||
const path = require('path');
|
||||
const path = require("path");
|
||||
const port = process.env.PORT || 5000;
|
||||
const mongoose = require("mongoose");
|
||||
const events = require("./models/events");
|
||||
const bodyParser = require("body-parser");
|
||||
app.use(bodyParser.json()); // to support JSON-encoded bodies
|
||||
app.use(
|
||||
bodyParser.urlencoded({
|
||||
// to support URL-encoded bodies
|
||||
extended: true,
|
||||
})
|
||||
bodyParser.urlencoded({
|
||||
// to support URL-encoded bodies
|
||||
extended: true,
|
||||
})
|
||||
);
|
||||
app.use(express.static(path.join(__dirname, 'client/build')));
|
||||
app.use(express.static(path.join(__dirname, "client/build")));
|
||||
app.use(
|
||||
cors({
|
||||
origin: "*",
|
||||
})
|
||||
cors({
|
||||
origin: "*",
|
||||
})
|
||||
);
|
||||
mongoose
|
||||
.connect(process.env.MONGO_URI, {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
})
|
||||
.then(() => console.log("connected"))
|
||||
.catch((err) => console.log(err));
|
||||
app.get('/', (req,res) =>{
|
||||
res.sendFile(path.join(__dirname+'/client/build/index.html'));
|
||||
});
|
||||
.connect(process.env.MONGO_URI, {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
})
|
||||
.then(() => console.log("connected"))
|
||||
.catch((err) => console.log(err));
|
||||
app.get("/", (req, res) => {
|
||||
res.sendFile(path.join(__dirname + "/client/build/index.html"));
|
||||
});
|
||||
app.get("/api/getEvents", async (req, res) => {
|
||||
try {
|
||||
const event = await events.find();
|
||||
if (!event) throw Error("something went wrong");
|
||||
console.log(event);
|
||||
res.status(200).json(event);
|
||||
} catch (err) {
|
||||
res.status(400).json({ msg: err });
|
||||
}
|
||||
try {
|
||||
const event = await events.find();
|
||||
if (!event) throw Error("something went wrong");
|
||||
console.log(event);
|
||||
res.status(200).json(event);
|
||||
} catch (err) {
|
||||
res.status(400).json({ msg: err });
|
||||
}
|
||||
});
|
||||
app.post("/api/createEvent", (req, res) => {
|
||||
let data = {
|
||||
name: req.body.name,
|
||||
type: req.body.type,
|
||||
address: req.body.address,
|
||||
time: req.body.time,
|
||||
created: { time: Date.now() },
|
||||
lat: req.body.lat,
|
||||
lon: req.body.lon,
|
||||
};
|
||||
events.create(data, (err) => {
|
||||
if (err) return res.status(400).json({ msg: err });
|
||||
// saved!
|
||||
res.status(200).json("ok");
|
||||
});
|
||||
let data = {
|
||||
name: req.body.name,
|
||||
type: req.body.type,
|
||||
address: req.body.address,
|
||||
time: req.body.time,
|
||||
created: { time: Date.now() },
|
||||
lat: req.body.lat,
|
||||
lon: req.body.lon,
|
||||
};
|
||||
events.create(data, (err) => {
|
||||
if (err) return res.status(400).json({ msg: err });
|
||||
// saved!
|
||||
res.status(200).json("ok");
|
||||
});
|
||||
});
|
||||
app.use((req, res, next) => {
|
||||
res.sendFile(path.join(__dirname+'/client/build/index.html'));
|
||||
})
|
||||
app.listen(port, () => {
|
||||
console.log(`Example app listening at http://localhost:${port}`);
|
||||
res.sendFile(path.join(__dirname + "/client/build/index.html"));
|
||||
});
|
||||
app.listen(port, () => {
|
||||
console.log(`Example app listening at http://localhost:${port}`);
|
||||
});
|
||||
Reference in new issue
Block a user