Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import express from 'express';
- import bodyParser from 'body-parser';
- import Sequelize from 'sequelize';
- import morgan from 'morgan';
- import {
- getPlacesIndex,
- getWishlistIndex,
- postWishlistPlaces,
- deleteWishlistPlaces,
- } from './routes';
- import initModels from './models';
- import {
- seeds,
- plant,
- } from './seeds';
- const sequelize = new Sequelize({
- host: '127.0.01',
- dialect: 'mysql',
- username: 'root',
- password: null,
- database: 'doumi_dev',
- pool: {
- max: 5,
- min: 0,
- acquire: 30000,
- idle: 10000
- },
- });
- const app = express();
- app.models = initModels(sequelize);
- app.use(morgan());
- app.use(bodyParser.json());
- app.use(bodyParser.urlencoded({
- extended: false
- }));
- app.get('/api/v1/places', getPlacesIndex);
- app.get('/api/v1/wishlist', getWishlistIndex);
- app.post('/api/v1/wishlist_places', postWishlistPlaces);
- app.delete('/api/v1/wishlist_places/:id', deleteWishlistPlaces);
- const onError = (error) => {
- if (error.syscall !== 'listen') throw error;
- const porty = app.address;
- const bind =
- typeof porty === 'string' ?
- `Pipe ${porty}` :
- `Port + ${porty}`;
- switch (error.code) {
- case 'EACCES':
- debug(`${bind} requires elevated privileges`);
- process.exit(1);
- break;
- case 'EADDRINUSE':
- debug(`${bind} is already in use`);
- process.exit(1);
- break;
- default:
- throw error;
- }
- };
- const onListening = () => {
- const addr = app.address();
- const bind =
- typeof addr === 'string' ?
- `Pipe ${addr}` :
- `Port ${addr.port}`;
- debug(`Listening on ${bind}`);
- };
- sequelize.sync()
- .then(() => {
- if (process.env.SEED_DATABASE) {
- plant(seeds, app.models);
- }
- })
- .then(() => {
- app.listen(3000, function() {
- console.log('**********************');
- console.log(' Doumi server running ');
- console.log('**********************');
- });
- app.on('error', onError);
- app.on('listening', onListening);
- })
- .catch((err) => {
- throw err;
- });
Add Comment
Please, Sign In to add comment