In your express project folder
yarn global add sequelize-cli
yarn add sequelize mysql2 dotenvother available dialect : pg pg-hstore | mariadb | sqlite3 | tedious
| { | |
| "name": "rails-react-demo", | |
| "version": "1.0.0", | |
| "description": "This README would normally document whatever steps are necessary to get the application up and running.", | |
| "main": "index.js", | |
| "directories": { | |
| "lib": "lib", | |
| "test": "test" | |
| }, | |
| "scripts": { |
| import React from 'react'; | |
| import './App.css'; | |
| const fetchTestDatas = function () { | |
| fetch('/api/v1/tests') | |
| .then(res => res.json()) | |
| .then((response) => { console.log("Test datas response", response); }) | |
| .catch((error) => { console.log("Error while fetching test datas", error); }) | |
| } |
| { | |
| "name": "client", | |
| "version": "0.1.0", | |
| "proxy": "http://127.0.0.1:3000", | |
| "private": true, | |
| "dependencies": { | |
| "react": "^16.9.0", | |
| "react-dom": "^16.9.0", | |
| "react-scripts": "3.1.1" | |
| }, |
| - Install passenger | |
| - Install nginx | |
| - Install nginx-passenger | |
| - Configure nginx-passenger for ruby path | |
| ## Nginx conf | |
| `/etc/nginx/site-available/domain.com` | |
| ```text | |
| map $http_upgrade $connection_upgrade { | |
| default upgrade; |
| let FS = require('fs'); | |
| // read the index.html from build folder | |
| let data = FS.readFileSync('./build/index.html', 'utf8'); | |
| function insertContent(fullContent, beforeWhat, newContent) { | |
| // get the position before which newContent has to be added | |
| const position = fullContent.indexOf(beforeWhat); | |
| // since splice can be used on arrays only |
| { | |
| "current": "0.1.6" | |
| } |
| ///////////////////// Exercice 1 /////////////////////// | |
| let num1 = 5; | |
| let num2 = 4; | |
| let i = 0; | |
| let result = 0; | |
| while(i < num1){ | |
| result = result + num2 | |
| i++; | |
| } |
| if(process.env.NODE_ENV == 'production'){ | |
| app.use(express.static(path.join(__dirname, 'client'))); | |
| app.get('*', function(req, res) { | |
| res.sendFile(path.join(__dirname, 'client', 'index.html')); | |
| }); | |
| } |
| Category.findByPk(req.params.id, { | |
| include: [ | |
| { | |
| model: Product, as: 'products', include: | |
| [ | |
| {model: Media, as: 'image'} | |
| ] | |
| } | |
| ] | |
| }) |