Skip to content

Commit a1ec551

Browse files
author
alves538
committed
app final correto
1 parent 28015f9 commit a1ec551

File tree

789 files changed

+70166
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

789 files changed

+70166
-0
lines changed

api/index.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const http = require('http')
2+
const URL = require('url')
3+
const fs = require('fs')
4+
const path = require('path')
5+
6+
const data = require('./urls.json')
7+
8+
function writeFile(cb) {
9+
fs.writeFile(
10+
path.join(__dirname, "urls.json"),
11+
JSON.stringify(data, null, 2),
12+
err => {
13+
if(err) throw err
14+
15+
cb(JSON.stringify({message: "ok"}))
16+
}
17+
)
18+
}
19+
20+
http.createServer((req, res) => {
21+
const { name, url, del } = URL.parse(req.url, true).query
22+
23+
res.writeHead(200, {
24+
'Access-Control-Allow-Origin': '*'
25+
})
26+
27+
// all resources
28+
if(!name || !url)
29+
return res.end(JSON.stringify(data))
30+
31+
if(del) {
32+
data.urls = data.urls.filter(item => String(item.url) !== String(url))
33+
return writeFile((message) => res.end(message))
34+
}
35+
36+
data.urls.push({name, url})
37+
38+
return writeFile((message) => res.end(message))
39+
40+
}).listen(3000, () => console.log('Api is running'))

api/urls.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"urls": [
3+
{
4+
"name": "Rockeseat",
5+
"url": "http://rocketseat.com.br"
6+
},
7+
{
8+
"name": "Google",
9+
"url": "http://google.com"
10+
},
11+
{
12+
"name": "Discord",
13+
"url": "http://discord.com"
14+
}
15+
]
16+
}

node_modules/.bin/is-ci

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/nodemon

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/nodetouch

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/nopt

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/rc

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/semver

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)