-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
37 lines (21 loc) · 686 Bytes
/
Copy pathserver.js
File metadata and controls
37 lines (21 loc) · 686 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';
var express = require('express');
var bodyParser = require('body-parser');
var cors = require('cors');
var myApp = require('./myApp');
var app = express();
var port = process.env.PORT || 3000;
app.use(cors());
app.use(bodyParser.urlencoded({extended:false}));
app.use('/public', express.static(process.cwd() + '/public'));
app.get('/', function(req, res){
res.sendFile(process.cwd() + '/views/index.html');
});
// your first API endpoint...
app.route("/api/shorturl/new")
.post( myApp.generateShortUrl )
app.route("/api/shorturl/:short_url")
.get(myApp.getShortUrl )
app.listen(port, function () {
console.log('Node.js listening ... ',port);
});