Spaces:
Runtime error
Runtime error
fix(render): provision postgres and require DATABASE_URL in production
Browse files- package.json +1 -1
- render.yaml +12 -0
- server.js +11 -3
package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
{
|
| 2 |
"name": "discord-like-app",
|
| 3 |
-
"version": "3.2.
|
| 4 |
"main": "server.js",
|
| 5 |
"scripts": {
|
| 6 |
"dev": "nodemon server.js",
|
|
|
|
| 1 |
{
|
| 2 |
"name": "discord-like-app",
|
| 3 |
+
"version": "3.2.11",
|
| 4 |
"main": "server.js",
|
| 5 |
"scripts": {
|
| 6 |
"dev": "nodemon server.js",
|
render.yaml
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
services:
|
| 2 |
- type: web
|
| 3 |
name: ultimate-chat-app
|
|
@@ -9,3 +13,11 @@ services:
|
|
| 9 |
envVars:
|
| 10 |
- key: NODE_ENV
|
| 11 |
value: production
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
databases:
|
| 2 |
+
- name: ultimate-chat-db
|
| 3 |
+
plan: free
|
| 4 |
+
|
| 5 |
services:
|
| 6 |
- type: web
|
| 7 |
name: ultimate-chat-app
|
|
|
|
| 13 |
envVars:
|
| 14 |
- key: NODE_ENV
|
| 15 |
value: production
|
| 16 |
+
- key: DATABASE_URL
|
| 17 |
+
fromDatabase:
|
| 18 |
+
name: ultimate-chat-db
|
| 19 |
+
property: connectionString
|
| 20 |
+
- key: JWT_SECRET
|
| 21 |
+
generateValue: true
|
| 22 |
+
- key: CORS_ORIGIN
|
| 23 |
+
value: "*"
|
server.js
CHANGED
|
@@ -108,10 +108,18 @@ app.get('/api/rtc-config', (req, res) => {
|
|
| 108 |
});
|
| 109 |
});
|
| 110 |
|
| 111 |
-
const
|
| 112 |
-
const
|
| 113 |
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
dialect: 'postgres',
|
| 116 |
logging: false,
|
| 117 |
protocol: 'postgres',
|
|
|
|
| 108 |
});
|
| 109 |
});
|
| 110 |
|
| 111 |
+
const isProduction = process.env.NODE_ENV === 'production';
|
| 112 |
+
const connectionString = process.env.DATABASE_URL;
|
| 113 |
|
| 114 |
+
if (isProduction && !connectionString) {
|
| 115 |
+
console.error('Missing DATABASE_URL in production. Add it in Render Environment settings or via render.yaml fromDatabase binding.');
|
| 116 |
+
process.exit(1);
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
const resolvedConnectionString = connectionString || 'postgres://postgres:postgres@localhost:5432/discord-app';
|
| 120 |
+
const isLocalConnection = resolvedConnectionString.includes('localhost') || resolvedConnectionString.includes('127.0.0.1');
|
| 121 |
+
|
| 122 |
+
const sequelize = new Sequelize(resolvedConnectionString, {
|
| 123 |
dialect: 'postgres',
|
| 124 |
logging: false,
|
| 125 |
protocol: 'postgres',
|