I'm on my localhost and when i start the server it shows nothing. When i go to localhost:8080/register it should show "asdasd" (as you can see in the code) but it doesnt work. Can you guys help me out? Thank you very much!
const U2F = require("u2f");
const Express = require("express");
const BodyParser = require("body-parser");
const Cors = require("cors");
const HTTP = require("http");
const FS = require("fs");
const session = require("express-session");
const APP_ID = "http://localhost:8080/";
var app = Express();
app.use(session({ secret: "test", cookie: { secure: true, maxAge: 60000 }, saveUninitialized: true, resave: true }));
app.use(BodyParser.json());
app.use(BodyParser.urlencoded({ extended: true }));
app.use(Cors({ origin: [APP_ID], credentials: true }));
var user;
app.get("/", (request, response, next) => {
response.end("Hello Test");
});
app.get("/register", (request, response, next) => {
console.log("asdasd");
});
app.post("/register", (request, response, next) => {});
app.get("/login", (request, response, next) => { });
app.post("/login", (request, response, next) => { });
HTTP.createServer(function (request, response){
response.end();
}).listen(8080);
1) for a start your are logging "asdasd" to the console and not responding to the request made at the "/register" endpoint, just modify your code to the one below.
app.get("/register", (request, response, next) => {
response.end("asdasd");
});
2) you have not actually created a server for app, http.createserver is not tied to app
modify your code to the below
const server = HTTP.createServer(app);
server.listen(8080,()=>console.log("server is listening on port 8080")
Just pass app(returned by express) inside HTTP.createServer
HTTP.createServer(app).listen(8080);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.