Skip to content

Instantly share code, notes, and snippets.

@lydemann
Created December 2, 2018 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lydemann/fd77b68b6f06ecd2ef723a8b3e6d9e9e to your computer and use it in GitHub Desktop.
Save lydemann/fd77b68b6f06ecd2ef723a8b3e6d9e9e to your computer and use it in GitHub Desktop.
index.js
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