Created
December 2, 2018 17:33
-
-
Save lydemann/fd77b68b6f06ecd2ef723a8b3e6d9e9e to your computer and use it in GitHub Desktop.
index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var path = require('path'); | |
const express = require('express'); | |
var cors = require('cors') | |
var app = express(); | |
app.use(cors()); | |
app.use('/assets', express.static(path.resolve(__dirname, 'assets'))); | |
var apiRoutes = express.Router(); | |
app.use('/api', apiRoutes) | |
apiRoutes.get('/todo-list', (req, res) => { | |
const todoList = [{ | |
id: 'task1', | |
title: 'Buy Milk', | |
description: 'Remember to buy milk' | |
}, | |
{ | |
id: 'task2', | |
title: 'Go to the gym', | |
description: 'Remember to work out' | |
} | |
]; | |
return res.json(todoList); | |
}); | |
apiRoutes.get('/fresh-todo-list', (req, res) => { | |
const todoList = [{ | |
id: 'task1', | |
title: 'New TODO 1!', | |
description: 'Remember to buy milk' | |
}, | |
{ | |
id: 'task2', | |
title: 'New TODO 2!', | |
description: 'Remember to work out' | |
} | |
]; | |
return res.json(todoList); | |
}); | |
const port = 8080; | |
app.listen(port, () => console.log(`Example app listening on port ${port}!`)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment