daily pastebin goal
52%
SHARE
TWEET

Untitled

a guest Dec 10th, 2018 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const express = require('express');
  2. const app = express();
  3. const port = 3000;
  4. var cors = require('cors')
  5. const connexion = require('./conf');
  6.  
  7. app.use(cors());
  8.  
  9. app.get('/api/employees', (req, res) => {
  10.   //todo recuperation des données (étape 2)
  11.  
  12.   connexion.query('SELECT * from employee', (err, results) => {
  13.     if (err) {
  14.       res.status(500).send('Erreur lors de la récupération des employés')
  15.     }else{
  16.       res.json(results);
  17.     }
  18.  
  19.   });
  20.  
  21. });
  22.  
  23. app.get('/api/movie', (req, res) => { 
  24.   connexion.query('SELECT * from movie', (err, results) => {
  25.     if(err){
  26.       res.status(500).send('Erreur lors de la recuperation des films');
  27.     }else{
  28.       res.json(results);
  29.     }
  30.   });
  31. });
  32.  
  33. app.get('/api/movie/name', (req, res)=>{
  34.   connexion.query('SELECT name from movie', (err, results)=>{
  35.     if(err){
  36.       res.status(500).send('Erreur lors de la recup');
  37.     }else{
  38.       res.json(results);
  39.     }
  40.   })
  41. })
  42.  
  43. app.listen(port, (err) => {
  44.   if (err) {
  45.     throw new Error('Something bad happened...');
  46.   }
  47.  
  48.   console.log(`Server is listening on ${port}`);
  49. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top