Skip to content

Commit

Permalink
update struktur nodejs
Browse files Browse the repository at this point in the history
  • Loading branch information
haifahrul committed Oct 10, 2024
1 parent 41bf881 commit 669b5b8
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
# ag-Grid Server-Side

- [Ag Grid](https://www.ag-grid.com/)
- Node.js Example
- Go Example
- Node.js Example (Version Node 12)
- Go Example (Version Go 1.21)
- MySQL
- PostgreSQL

Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
{
"name": "ag-grid-server-side-demo",
"version": "1.0.0",
"description": "A simple demo app showing how to perform server-side operations using ag-Grid with node.js and MySQL.",
"name": "go-server-side-ag-grid",
"version": "2.0.0",
"description": "A simple demo app showing how to perform server-side operations using ag-Grid with node.js and MySQL. Golang with PostgreSQL and MySQL",
"repository": {
"type": "git",
"url": "go-server-side-ag-grid"
},
"main": "index.js",
"scripts": {
"start": "babel-node ./server/server.js",
"dev": "nodemon --exec babel-node ./server/server.js"
"start": "babel-node ./server/nodejs/server.js",
"dev": "nodemon --exec babel-node ./server/nodejs/server.js"
},
"keywords": [],
"author": "Robert Clarke",
"author": "haifahrul",
"license": "MIT",
"devDependencies": {
"babel-cli": "^6.26.0",
Expand Down Expand Up @@ -36,9 +40,5 @@
"express": "^4.16.2",
"mysql": "2.16.0",
"node-fetch": "^2.6.1"
},
"repository": {
"type": "git",
"url": "ag-grid-server-side-demo"
}
}
File renamed without changes.
56 changes: 56 additions & 0 deletions server/nodejs/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import webpack from 'webpack';
import webpackMiddleware from 'webpack-dev-middleware';
import webpackConfig from '../../webpack.config.js';
import express from 'express';
import bodyParser from 'body-parser';
import fetch from 'node-fetch'
import OlympicWinnersService from './olympicWinnersService';

const app = express();
app.use(webpackMiddleware(webpack(webpackConfig)));
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());

app.post('/nodeOlympicWinners', function (req, res) {
OlympicWinnersService.getData(req.body, (rows, lastRow) => {
res.json({rows: rows, lastRow: lastRow});
});
});

app.post('/goOlympicWinnersMySQL', function (req, res) {
console.log('---BODY---', req.body)
console.log('')
fetch('http://localhost:8080/mysql-olympic-winners', {
method: 'post',
body: JSON.stringify(req.body),
headers: {"Content-Type": "application/json; charset=utf-8;"}
})
.then(httpResponse => httpResponse.json())
.then(response => {
res.json({rows: response.rows, lastRow: response.lastRow});
})
.catch(error => {
console.error(error);
})
});

app.post('/goOlympicWinnersPostgreSQL', function (req, res) {
console.log('---BODY---', req.body)
console.log('')
fetch('http://localhost:8080/postgre-olympic-winners', {
method: 'post',
body: JSON.stringify(req.body),
headers: {"Content-Type": "application/json; charset=utf-8;"}
})
.then(httpResponse => httpResponse.json())
.then(response => {
res.json({rows: response.rows, lastRow: response.lastRow});
})
.catch(error => {
console.error(error);
})
});

app.listen(4000, () => {
console.log('Started on localhost:4000');
});
2 changes: 1 addition & 1 deletion server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import webpackConfig from '../webpack.config.js';
import express from 'express';
import bodyParser from 'body-parser';
import fetch from 'node-fetch'
import OlympicWinnersService from './olympicWinnersService';
import OlympicWinnersService from './nodejs/olympicWinnersService.js';

const app = express();
app.use(webpackMiddleware(webpack(webpackConfig)));
Expand Down

0 comments on commit 669b5b8

Please sign in to comment.