Update app.js
Browse files
app.js
CHANGED
|
@@ -4,11 +4,17 @@ const cors = require('cors');
|
|
| 4 |
const { findAll, insert, findById, updateById, deleteById, createNewSheet, getSheetNames, deleteSheet } = require('./store');// assuming your Google Sheets script is named js
|
| 5 |
|
| 6 |
const app = express();
|
| 7 |
-
const
|
|
|
|
| 8 |
|
| 9 |
app.use(bodyParser.json());
|
| 10 |
app.use(cors())
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
// Get all data
|
| 13 |
app.get('/data', async (req, res) => {
|
| 14 |
try {
|
|
@@ -101,6 +107,11 @@ app.delete('/sheet/:name', async (req, res) => {
|
|
| 101 |
|
| 102 |
|
| 103 |
// Start the server
|
| 104 |
-
app.listen(
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
});
|
|
|
|
| 4 |
const { findAll, insert, findById, updateById, deleteById, createNewSheet, getSheetNames, deleteSheet } = require('./store');// assuming your Google Sheets script is named js
|
| 5 |
|
| 6 |
const app = express();
|
| 7 |
+
const PORT = 7860;
|
| 8 |
+
const HOST = '0.0.0.0';
|
| 9 |
|
| 10 |
app.use(bodyParser.json());
|
| 11 |
app.use(cors())
|
| 12 |
|
| 13 |
+
app.get('/', (req, res) => {
|
| 14 |
+
res.setHeader('Content-Type', 'text/plain');
|
| 15 |
+
res.end('This is LinDB \n\nSearch all (get) : /data\nSearch by id (get) : /data/:<id>\nInsert (post) : /data\nUpdate (put) : /data:<id>\nDelete (delete) : /data/:<id>\nCreate sheet (post): /sheet/\nGet sheets (get): /data\nDelete sheet (delete) : /data/:<name>');
|
| 16 |
+
})
|
| 17 |
+
|
| 18 |
// Get all data
|
| 19 |
app.get('/data', async (req, res) => {
|
| 20 |
try {
|
|
|
|
| 107 |
|
| 108 |
|
| 109 |
// Start the server
|
| 110 |
+
app.listen(PORT, HOST, () => {
|
| 111 |
+
if (HOST == '0.0.0.0') {
|
| 112 |
+
console.log(`Running on http://127.0.0.1:${PORT}`);
|
| 113 |
+
} else {
|
| 114 |
+
console.log(`Running on http://${HOST}:${PORT}`);
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
});
|