urlshortener/server.js
2020-10-14 12:08:47 +09:00

28 lines
631 B
JavaScript

require('dotenv').config();
const express = require('express');
const cors = require('cors');
const app = express();
// Basic Configuration
const port = process.env.PORT || 3000;
app.use(cors());
/* This project needs to parse POST bodies */
// You should mount body-parser here
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.get('/api/hello', function(req, res) {
res.json({ greeting: 'hello API' });
});
app.listen(port, function() {
console.log(`Listening on port ${port}`);
});