-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
45 lines (38 loc) · 1.17 KB
/
index.ts
File metadata and controls
45 lines (38 loc) · 1.17 KB
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
38
39
40
41
42
43
44
45
// <reference path="typings/index.d.ts" />
import * as express from "express";
import * as bodyParser from "body-parser";
import * as Quote from "./entities/codes";
import * as mongoose from "mongoose";
import * as cors from "cors";
const restful = require('node-restful');
// ===============
// COMMON VARIABLES
// ===============
let appPort: number = (process.env.PORT || 8080);
let connectionString: string = `mongodb://heroku_wk7zz0k5:2fgj4rr1flbc8cqu94b38g85lc@ds111565.mlab.com:11565/heroku_wk7zz0k5`;
// ===============
// Express App
// ===============
const app = express();
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
app.set("port", appPort);
const codeApi = restful.model("quote", Quote.schema)
.methods(["get", "post", "put", "delete"])
.register(app, "/api/code");
// ===============
// DB
// ===============
mongoose.connect(connectionString);
// ===============
// SERVER
// ===============
let port:number = app.get("port");
const server = app.listen(port, () => {
console.log("connectionString is: " + connectionString);
console.log("port is: " + port);
console.log("Server started listening...");
});