Guest User

Untitled

a guest
Jul 18th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. 'use strict';
  2.  
  3. const express = require('express'),
  4. bodyParser = require('body-parser'),
  5. morgan = require('morgan'),
  6. db = require('./db.js'),
  7. router = require('../routes/index');
  8.  
  9. const app = express();
  10. const PORT = 7500;
  11.  
  12. app.use(morgan('combined'));
  13. app.use(bodyParser.json());
  14.  
  15. app.use((req, res, next) => {
  16. res.header('Content-Type', 'application/json');
  17. next();
  18. });
  19.  
  20. router(app, db);
  21.  
  22. //drop and resync with { force: true }
  23. db.sequelize.sync({
  24. force: false
  25. }).then(() => {
  26. app.listen(PORT, () => {
  27. console.log('We are live on port :', PORT);
  28. });
  29. });
  30.  
  31. /* CREATE an account */
  32. app.post('/create_account', function (req, res) {
  33.  
  34. // Grab data from http request
  35. const data = {
  36. username: req.body.username,
  37. name: req.body.name,
  38. firstname: req.body.firstname,
  39. email: req.body.email,
  40. location: req.body.location,
  41. type: req.body.type
  42. };
  43.  
  44. db.users.create({
  45. username: data.username,
  46. name: data.name,
  47. firstname: data.firstname,
  48. email: data.email,
  49. location: data.location,
  50. type: data.type
  51. }).then(newUser => {
  52. res.json(newUser);
  53. });
  54.  
  55. });
Add Comment
Please, Sign In to add comment