Skip to content
Permalink
Browse files

Add GET methods

  • Loading branch information
nedzadalibegovic committed Jan 3, 2020
1 parent 889fb25 commit f9656b8e3f73da76d049c2e6d5cadc6a9b909f11
Showing with 918 additions and 4 deletions.
  1. +13 −0 .vscode/launch.json
  2. +24 −0 api/routes/images.js
  3. +19 −0 app.js
  4. +0 −1 b2_operations.js
  5. +854 −1 package-lock.json
  6. +8 −2 package.json
@@ -0,0 +1,13 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Node: Nodemon",
"processId": "${command:PickProcess}",
"restart": true,
"protocol": "inspector",
},
]
}
@@ -0,0 +1,24 @@
const express = require('express');
const Image = require('../models/image');

const router = express.Router();

router.get('/', async (req, res) => {
try {
let images = await Image.find();
res.status(200).json(images);
} catch (err) {
res.status(500).json({ message: err });
}
});

router.get('/:id', async (req, res) => {
try {
let found = await Image.findById(req.params.id);
res.status(200).json(found);
} catch (err) {
res.status(500).json({ message: err });
}
});

module.exports = router;
19 app.js
@@ -0,0 +1,19 @@
const express = require('express');
const mongoose = require('mongoose');
const cors = require('cors');
const imagesRoute = require('./api/routes/images');

const app = express();

// middlewares
app.use(cors());
app.use('/api/v1/images', imagesRoute);

// routes
app.get('/', (req,res) => {
res.redirect('/api/v1/images');
});

mongoose.connect(process.env.MONGO, { useUnifiedTopology: true, useNewUrlParser: true });

app.listen(process.env.PORT);
@@ -1,4 +1,3 @@
require('dotenv').config();
const fetch = require('node-fetch');

const authorize_account = async () => {

0 comments on commit f9656b8

Please sign in to comment.
You can’t perform that action at this time.