mirror of
https://github.com/originalmk/skrytka-app.git
synced 2025-01-18 08:19:17 +00:00
Changed the way app is run
Now Express serves React client/build directory as static files. All unmatched requests are answered with index.html file.
This commit is contained in:
parent
16825071b3
commit
e9ad514166
@ -5,6 +5,7 @@ To start this application you need to:
|
|||||||
- Setup some database and user with permissions to it
|
- Setup some database and user with permissions to it
|
||||||
- Create .env file in the main directory and fill it in with fields DB_USER, DB_PASS, DB_HOST, DB_PORT and DB_NAME. In case of confusion you may check exemplary .env file saved as .env.example in the root directory of this repository.
|
- Create .env file in the main directory and fill it in with fields DB_USER, DB_PASS, DB_HOST, DB_PORT and DB_NAME. In case of confusion you may check exemplary .env file saved as .env.example in the root directory of this repository.
|
||||||
2. Run both SQL scripts, which are located in the main directory. For app to be usable it is also recommended to insert some data to the database.
|
2. Run both SQL scripts, which are located in the main directory. For app to be usable it is also recommended to insert some data to the database.
|
||||||
3. Run `npm start` in the main directory
|
3. Run `npm build` in the client directory.
|
||||||
4. Run `npm start` in the client/ directory
|
4. Run `npm start` in the main directory
|
||||||
5. App will run on localhost:3000
|
5. App will run on localhost:5000
|
||||||
|
Note: pm2 or/and nginx may be used to run this app for production
|
||||||
|
12
app.js
12
app.js
@ -4,12 +4,13 @@ const session = require('express-session');
|
|||||||
const responseTime = require('response-time');
|
const responseTime = require('response-time');
|
||||||
const types = require('pg').types;
|
const types = require('pg').types;
|
||||||
const validator = require('validator');
|
const validator = require('validator');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const db = pgp(`postgres://${process.env.DB_USER}:${process.env.DB_PASS}@${process.env.DB_HOST}:${process.env.DB_PORT}/${process.env.DB_NAME}`);
|
const db = pgp(`postgres://${process.env.DB_USER}:${process.env.DB_PASS}@${process.env.DB_HOST}:${process.env.DB_PORT}/${process.env.DB_NAME}`);
|
||||||
const port = 3001;
|
const port = 5000;
|
||||||
|
|
||||||
class Point {
|
class Point {
|
||||||
x;
|
x;
|
||||||
@ -43,6 +44,9 @@ types.setTypeParser(603, function(rectangleStr) {
|
|||||||
return new Rectangle(lowerBottomPoint, size);
|
return new Rectangle(lowerBottomPoint, size);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Frontend hosting:
|
||||||
|
app.use(express.static(path.join(__dirname, 'client/build')));
|
||||||
|
|
||||||
app.use(session({
|
app.use(session({
|
||||||
store: new (require('connect-pg-simple')(session))({
|
store: new (require('connect-pg-simple')(session))({
|
||||||
pgPromise: db,
|
pgPromise: db,
|
||||||
@ -593,6 +597,12 @@ app.get('/simulate-logout', (req, res) => {
|
|||||||
res.send(`Logged out!`);
|
res.send(`Logged out!`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// This should remain at the end of all routes
|
||||||
|
// It will direct every not matched route to index.html file
|
||||||
|
app.get('/*', function (req, res) {
|
||||||
|
res.sendFile(path.join(__dirname, 'client/build', 'index.html'));
|
||||||
|
});
|
||||||
|
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
console.log(`Skrytka.app słucha na porcie ${port}...`);
|
console.log(`Skrytka.app słucha na porcie ${port}...`);
|
||||||
});
|
});
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
"test": "react-scripts test",
|
"test": "react-scripts test",
|
||||||
"eject": "react-scripts eject"
|
"eject": "react-scripts eject"
|
||||||
},
|
},
|
||||||
"proxy": "http://localhost:3001",
|
"proxy": "http://localhost:5000",
|
||||||
"browserslist": {
|
"browserslist": {
|
||||||
"production": [
|
"production": [
|
||||||
">0.2%",
|
">0.2%",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user