mirror of
https://gitlab.com/nekoya/web.git
synced 2024-11-14 02:16:19 +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')
|
app.set('view engine', 'ejs')
|
||||||
|
|
||||||
const indexRouter = require('./routes/index');
|
const indexRouter = require('./routes/index');
|
||||||
|
const api = require('./routes/api');
|
||||||
|
|
||||||
app.use('/', indexRouter);
|
app.use('/', indexRouter);
|
||||||
|
app.use('/api', api);
|
||||||
|
|
||||||
app.listen('3000', ()=> {
|
app.listen('3000', ()=> {
|
||||||
console.log('Server sudah berjalan di port 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