mirror of
https://gitlab.com/nekoya/web.git
synced 2024-11-12 17:36:21 +01:00
[WIP] API Support
This commit is contained in:
parent
b98fdb5a6c
commit
32ff0299ba
2 changed files with 21 additions and 0 deletions
2
index.js
2
index.js
|
@ -7,8 +7,10 @@ app.use(express.static('public'))
|
|||
app.set('view engine', 'ejs')
|
||||
|
||||
const indexRouter = require('./routes/index');
|
||||
const api = require('./routes/api');
|
||||
|
||||
app.use('/', indexRouter);
|
||||
app.use('/api', api);
|
||||
|
||||
app.listen('3000', ()=> {
|
||||
console.log('Server sudah berjalan di port 3000')
|
||||
|
|
19
routes/api.js
Normal file
19
routes/api.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
const express = require('express')
|
||||
const router = express.Router()
|
||||
const db = require('../modules/db')
|
||||
|
||||
router.get('/getproducts', (req, res) => {
|
||||
const conn = db.connect();
|
||||
conn.execute('SELECT * FROM `product`', [], function(err, results) {
|
||||
res.json(results);
|
||||
});
|
||||
})
|
||||
|
||||
router.get('/getproduct', (req, res) => {
|
||||
const conn = db.connect();
|
||||
conn.execute('SELECT * FROM `product` WHERE `model` = ?', [req.query.id], function(err, results) {
|
||||
res.json(results);
|
||||
});
|
||||
})
|
||||
|
||||
module.exports = router;
|
Loading…
Reference in a new issue